diff --git a/lib/PhpParser/Node/Expr/Closure.php b/lib/PhpParser/Node/Expr/Closure.php index 2d40fa55f1..0f17e53ab5 100644 --- a/lib/PhpParser/Node/Expr/Closure.php +++ b/lib/PhpParser/Node/Expr/Closure.php @@ -7,7 +7,7 @@ use PhpParser\Node\Expr; use PhpParser\Node\FunctionLike; -class Closure extends Expr implements FunctionLike { +class Closure extends Expr implements FunctionLike, Node\StmtsIterable { /** @var bool Whether the closure is static */ public $static; /** @var bool Whether to return by reference */ diff --git a/lib/PhpParser/Node/Stmt/Case_.php b/lib/PhpParser/Node/Stmt/Case_.php index fe825e4192..bdc50a7597 100644 --- a/lib/PhpParser/Node/Stmt/Case_.php +++ b/lib/PhpParser/Node/Stmt/Case_.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class Case_ extends Node\Stmt { +class Case_ extends Node\Stmt implements Node\StmtsIterable { /** @var null|Node\Expr Condition (null for default) */ public $cond; /** @var Node\Stmt[] Statements */ diff --git a/lib/PhpParser/Node/Stmt/Catch_.php b/lib/PhpParser/Node/Stmt/Catch_.php index bbd1f523ad..d804658c84 100644 --- a/lib/PhpParser/Node/Stmt/Catch_.php +++ b/lib/PhpParser/Node/Stmt/Catch_.php @@ -5,7 +5,7 @@ use PhpParser\Node; use PhpParser\Node\Expr; -class Catch_ extends Node\Stmt { +class Catch_ extends Node\Stmt implements Node\StmtsIterable { /** @var Node\Name[] Types of exceptions to catch */ public $types; /** @var Expr\Variable|null Variable for exception */ diff --git a/lib/PhpParser/Node/Stmt/Do_.php b/lib/PhpParser/Node/Stmt/Do_.php index f8328101ef..6ed1f67e78 100644 --- a/lib/PhpParser/Node/Stmt/Do_.php +++ b/lib/PhpParser/Node/Stmt/Do_.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class Do_ extends Node\Stmt { +class Do_ extends Node\Stmt implements Node\StmtsIterable { /** @var Node\Stmt[] Statements */ public $stmts; /** @var Node\Expr Condition */ diff --git a/lib/PhpParser/Node/Stmt/ElseIf_.php b/lib/PhpParser/Node/Stmt/ElseIf_.php index 5d95169515..0b66fb4eeb 100644 --- a/lib/PhpParser/Node/Stmt/ElseIf_.php +++ b/lib/PhpParser/Node/Stmt/ElseIf_.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class ElseIf_ extends Node\Stmt { +class ElseIf_ extends Node\Stmt implements Node\StmtsIterable { /** @var Node\Expr Condition */ public $cond; /** @var Node\Stmt[] Statements */ diff --git a/lib/PhpParser/Node/Stmt/Else_.php b/lib/PhpParser/Node/Stmt/Else_.php index 03cf37a869..30309383b9 100644 --- a/lib/PhpParser/Node/Stmt/Else_.php +++ b/lib/PhpParser/Node/Stmt/Else_.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class Else_ extends Node\Stmt { +class Else_ extends Node\Stmt implements Node\StmtsIterable { /** @var Node\Stmt[] Statements */ public $stmts; diff --git a/lib/PhpParser/Node/Stmt/Finally_.php b/lib/PhpParser/Node/Stmt/Finally_.php index 351550e79a..51074b7c40 100644 --- a/lib/PhpParser/Node/Stmt/Finally_.php +++ b/lib/PhpParser/Node/Stmt/Finally_.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class Finally_ extends Node\Stmt { +class Finally_ extends Node\Stmt implements Node\StmtsIterable { /** @var Node\Stmt[] Statements */ public $stmts; diff --git a/lib/PhpParser/Node/Stmt/For_.php b/lib/PhpParser/Node/Stmt/For_.php index 7afd2e25eb..c334e24b62 100644 --- a/lib/PhpParser/Node/Stmt/For_.php +++ b/lib/PhpParser/Node/Stmt/For_.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class For_ extends Node\Stmt { +class For_ extends Node\Stmt implements Node\StmtsIterable { /** @var Node\Expr[] Init expressions */ public $init; /** @var Node\Expr[] Loop conditions */ diff --git a/lib/PhpParser/Node/Stmt/Foreach_.php b/lib/PhpParser/Node/Stmt/Foreach_.php index b0230cfe69..a7423f9a7d 100644 --- a/lib/PhpParser/Node/Stmt/Foreach_.php +++ b/lib/PhpParser/Node/Stmt/Foreach_.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class Foreach_ extends Node\Stmt { +class Foreach_ extends Node\Stmt implements Node\StmtsIterable { /** @var Node\Expr Expression to iterate */ public $expr; /** @var null|Node\Expr Variable to assign key to */ diff --git a/lib/PhpParser/Node/Stmt/Function_.php b/lib/PhpParser/Node/Stmt/Function_.php index e47554a389..bb0a16adfb 100644 --- a/lib/PhpParser/Node/Stmt/Function_.php +++ b/lib/PhpParser/Node/Stmt/Function_.php @@ -5,7 +5,7 @@ use PhpParser\Node; use PhpParser\Node\FunctionLike; -class Function_ extends Node\Stmt implements FunctionLike { +class Function_ extends Node\Stmt implements FunctionLike, Node\StmtsIterable { /** @var bool Whether function returns by reference */ public $byRef; /** @var Node\Identifier Name */ diff --git a/lib/PhpParser/Node/Stmt/If_.php b/lib/PhpParser/Node/Stmt/If_.php index 57c9290eda..72b16d0124 100644 --- a/lib/PhpParser/Node/Stmt/If_.php +++ b/lib/PhpParser/Node/Stmt/If_.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class If_ extends Node\Stmt { +class If_ extends Node\Stmt implements Node\StmtsIterable { /** @var Node\Expr Condition expression */ public $cond; /** @var Node\Stmt[] Statements */ diff --git a/lib/PhpParser/Node/Stmt/Namespace_.php b/lib/PhpParser/Node/Stmt/Namespace_.php index 7ae38f4b22..f174ed8c7c 100644 --- a/lib/PhpParser/Node/Stmt/Namespace_.php +++ b/lib/PhpParser/Node/Stmt/Namespace_.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class Namespace_ extends Node\Stmt { +class Namespace_ extends Node\Stmt implements Node\StmtsIterable { /* For use in the "kind" attribute */ public const KIND_SEMICOLON = 1; public const KIND_BRACED = 2; diff --git a/lib/PhpParser/Node/Stmt/TryCatch.php b/lib/PhpParser/Node/Stmt/TryCatch.php index 3587d6ba14..58913540ca 100644 --- a/lib/PhpParser/Node/Stmt/TryCatch.php +++ b/lib/PhpParser/Node/Stmt/TryCatch.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class TryCatch extends Node\Stmt { +class TryCatch extends Node\Stmt implements Node\StmtsIterable { /** @var Node\Stmt[] Statements */ public $stmts; /** @var Catch_[] Catches */ diff --git a/lib/PhpParser/Node/Stmt/While_.php b/lib/PhpParser/Node/Stmt/While_.php index f13b7e7a6e..e2ecc08044 100644 --- a/lib/PhpParser/Node/Stmt/While_.php +++ b/lib/PhpParser/Node/Stmt/While_.php @@ -4,7 +4,7 @@ use PhpParser\Node; -class While_ extends Node\Stmt { +class While_ extends Node\Stmt implements Node\StmtsIterable { /** @var Node\Expr Condition */ public $cond; /** @var Node\Stmt[] Statements */ diff --git a/lib/PhpParser/Node/StmtsIterable.php b/lib/PhpParser/Node/StmtsIterable.php new file mode 100644 index 0000000000..eaddcb37da --- /dev/null +++ b/lib/PhpParser/Node/StmtsIterable.php @@ -0,0 +1,14 @@ +createForNewestSupportedVersion(); + $nodes = $parser->parse(<<<'CODE_SAMPLE' + $value) { + $value = 100; + $value = 100; + } +} +CODE_SAMPLE + ); + + $nodeFinder = new NodeFinder(); + $stmtsIterables = $nodeFinder->findInstanceOf($nodes, StmtsIterable::class); + + $this->assertCount(2, $stmtsIterables); +// $this->assertInstanceOf(Function_::class, $stmtsIterables[0]); +// $this->assertInstanceOf(Foreach_::class, $stmtsIterables[1]); + } +}