Skip to content

Commit 27c7b77

Browse files
committed
Add Functionlike interface
microsoft#162
1 parent 450aba1 commit 27c7b77

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/FunctionLike.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/*---------------------------------------------------------------------------------------------
3+
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
namespace Microsoft\PhpParser;
8+
9+
/**
10+
* Interface for recognizing functions easily.
11+
* Each Node that implements this interface can be considered a function.
12+
*/
13+
interface FunctionLike {}

src/Node/Expression/AnonymousFunctionCreationExpression.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
namespace Microsoft\PhpParser\Node\Expression;
88

9+
use Microsoft\PhpParser\FunctionLike;
910
use Microsoft\PhpParser\Node\Expression;
1011
use Microsoft\PhpParser\Node\FunctionBody;
1112
use Microsoft\PhpParser\Node\FunctionHeader;
1213
use Microsoft\PhpParser\Node\FunctionReturnType;
1314
use Microsoft\PhpParser\Node\FunctionUseClause;
1415
use Microsoft\PhpParser\Token;
1516

16-
class AnonymousFunctionCreationExpression extends Expression {
17+
class AnonymousFunctionCreationExpression extends Expression implements FunctionLike {
1718
/** @var Token | null */
1819
public $staticModifier;
1920

src/Node/MethodDeclaration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
namespace Microsoft\PhpParser\Node;
88

9+
use Microsoft\PhpParser\FunctionLike;
910
use Microsoft\PhpParser\Node;
1011
use Microsoft\PhpParser\Token;
1112
use Microsoft\PhpParser\TokenKind;
1213

13-
class MethodDeclaration extends Node {
14+
class MethodDeclaration extends Node implements FunctionLike {
1415
/** @var Token[] */
1516
public $modifiers;
1617

src/Node/Statement/FunctionDeclaration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
namespace Microsoft\PhpParser\Node\Statement;
88

9+
use Microsoft\PhpParser\FunctionLike;
910
use Microsoft\PhpParser\NamespacedNameInterface;
1011
use Microsoft\PhpParser\NamespacedNameTrait;
1112
use Microsoft\PhpParser\Node\FunctionBody;
1213
use Microsoft\PhpParser\Node\FunctionHeader;
1314
use Microsoft\PhpParser\Node\FunctionReturnType;
1415
use Microsoft\PhpParser\Node\StatementNode;
1516

16-
class FunctionDeclaration extends StatementNode implements NamespacedNameInterface {
17+
class FunctionDeclaration extends StatementNode implements NamespacedNameInterface, FunctionLike {
1718
use FunctionHeader, FunctionReturnType, FunctionBody;
1819
use NamespacedNameTrait;
1920

0 commit comments

Comments
 (0)