diff --git a/lib/PhpParser/Node/ContainsStmts.php b/lib/PhpParser/Node/ContainsStmts.php new file mode 100644 index 0000000000..cbae25affa --- /dev/null +++ b/lib/PhpParser/Node/ContainsStmts.php @@ -0,0 +1,15 @@ +stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/Case_.php b/lib/PhpParser/Node/Stmt/Case_.php index a06ca1832e..fa34d6f9e2 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\ContainsStmts { /** @var null|Node\Expr Condition (null for default) */ public ?Node\Expr $cond; /** @var Node\Stmt[] Statements */ @@ -30,4 +30,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_Case'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/Catch_.php b/lib/PhpParser/Node/Stmt/Catch_.php index e8d39c9cce..bdc073cc2c 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\ContainsStmts { /** @var Node\Name[] Types of exceptions to catch */ public array $types; /** @var Expr\Variable|null Variable for exception */ @@ -37,4 +37,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_Catch'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/ClassMethod.php b/lib/PhpParser/Node/Stmt/ClassMethod.php index 59c0519ea6..6b03b120a0 100644 --- a/lib/PhpParser/Node/Stmt/ClassMethod.php +++ b/lib/PhpParser/Node/Stmt/ClassMethod.php @@ -6,7 +6,7 @@ use PhpParser\Node; use PhpParser\Node\FunctionLike; -class ClassMethod extends Node\Stmt implements FunctionLike { +class ClassMethod extends Node\Stmt implements FunctionLike, Node\ContainsStmts { /** @var int Flags */ public int $flags; /** @var bool Whether to return by reference */ @@ -90,7 +90,14 @@ public function getReturnType() { return $this->returnType; } - public function getStmts(): ?array { + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + if ($this->stmts === null) { + return []; + } + return $this->stmts; } diff --git a/lib/PhpParser/Node/Stmt/Do_.php b/lib/PhpParser/Node/Stmt/Do_.php index 6124442881..f7ccf25921 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\ContainsStmts { /** @var Node\Stmt[] Statements */ public array $stmts; /** @var Node\Expr Condition */ @@ -30,4 +30,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_Do'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/ElseIf_.php b/lib/PhpParser/Node/Stmt/ElseIf_.php index b26d59ce5f..ceb91c5ae7 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\ContainsStmts { /** @var Node\Expr Condition */ public Node\Expr $cond; /** @var Node\Stmt[] Statements */ @@ -30,4 +30,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_ElseIf'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/Else_.php b/lib/PhpParser/Node/Stmt/Else_.php index 3d2b066ec9..7c27235231 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\ContainsStmts { /** @var Node\Stmt[] Statements */ public array $stmts; @@ -26,4 +26,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_Else'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/Finally_.php b/lib/PhpParser/Node/Stmt/Finally_.php index 69ecf25373..9f06ba1d1c 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\ContainsStmts { /** @var Node\Stmt[] Statements */ public array $stmts; @@ -26,4 +26,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_Finally'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/For_.php b/lib/PhpParser/Node/Stmt/For_.php index 6f2fbb9e3a..ea7e3526e8 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\ContainsStmts { /** @var Node\Expr[] Init expressions */ public array $init; /** @var Node\Expr[] Loop conditions */ @@ -44,4 +44,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_For'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/Foreach_.php b/lib/PhpParser/Node/Stmt/Foreach_.php index c5d9a8b132..7a81580947 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\ContainsStmts { /** @var Node\Expr Expression to iterate */ public Node\Expr $expr; /** @var null|Node\Expr Variable to assign key to */ @@ -47,4 +47,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_Foreach'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/Function_.php b/lib/PhpParser/Node/Stmt/Function_.php index 2111bab749..fa08f43083 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\ContainsStmts { /** @var bool Whether function returns by reference */ public bool $byRef; /** @var Node\Identifier Name */ diff --git a/lib/PhpParser/Node/Stmt/If_.php b/lib/PhpParser/Node/Stmt/If_.php index 544390ff5e..1a1f649310 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\ContainsStmts { /** @var Node\Expr Condition expression */ public Node\Expr $cond; /** @var Node\Stmt[] Statements */ @@ -43,4 +43,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_If'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/Namespace_.php b/lib/PhpParser/Node/Stmt/Namespace_.php index f5b59ad6e3..14fda7394c 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\ContainsStmts { /* For use in the "kind" attribute */ public const KIND_SEMICOLON = 1; public const KIND_BRACED = 2; @@ -34,4 +34,15 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_Namespace'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + if ($this->stmts === null) { + return []; + } + + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/TryCatch.php b/lib/PhpParser/Node/Stmt/TryCatch.php index 6414c46c94..7db3df1383 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\ContainsStmts { /** @var Node\Stmt[] Statements */ public array $stmts; /** @var Catch_[] Catches */ @@ -34,4 +34,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_TryCatch'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/lib/PhpParser/Node/Stmt/While_.php b/lib/PhpParser/Node/Stmt/While_.php index 2f7aed2343..f21ebcada9 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\ContainsStmts { /** @var Node\Expr Condition */ public Node\Expr $cond; /** @var Node\Stmt[] Statements */ @@ -30,4 +30,11 @@ public function getSubNodeNames(): array { public function getType(): string { return 'Stmt_While'; } + + /** + * @return Node\Stmt[] + */ + public function getStmts(): array { + return $this->stmts; + } } diff --git a/test/PhpParser/Node/Stmt/ClassMethodTest.php b/test/PhpParser/Node/Stmt/ClassMethodTest.php index 17bb3ec508..003561eb76 100644 --- a/test/PhpParser/Node/Stmt/ClassMethodTest.php +++ b/test/PhpParser/Node/Stmt/ClassMethodTest.php @@ -117,6 +117,6 @@ public function testFunctionLike(): void { ]); $this->assertTrue($method->returnsByRef()); - $this->assertNull($method->getStmts()); + $this->assertSame([], $method->getStmts()); } }