Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/PhpParser/Node/ContainsStmts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace PhpParser\Node;

/**
* @property Stmt[]|null $stmts
*/
interface ContainsStmts extends \PhpParser\Node {
/**
* @return Stmt[]
*/
public function getStmts(): array;
}
2 changes: 1 addition & 1 deletion lib/PhpParser/Node/Expr/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\ContainsStmts {
/** @var bool Whether the closure is static */
public bool $static;
/** @var bool Whether to return by reference */
Expand Down
10 changes: 9 additions & 1 deletion lib/PhpParser/Node/Stmt/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PhpParser\Node\Stmt;

use PhpParser\Node\ContainsStmts;
use PhpParser\Node\Stmt;

class Block extends Stmt {
class Block extends Stmt implements ContainsStmts {
/** @var Stmt[] Statements */
public array $stmts;

Expand All @@ -26,4 +27,11 @@ public function getType(): string {
public function getSubNodeNames(): array {
return ['stmts'];
}

/**
* @return Stmt[]
*/
public function getStmts(): array {
return $this->stmts;
}
}
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/Case_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
}
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/Catch_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
}
11 changes: 9 additions & 2 deletions lib/PhpParser/Node/Stmt/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/Do_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
}
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/ElseIf_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
}
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/Else_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/Finally_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/For_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
}
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/Foreach_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion lib/PhpParser/Node/Stmt/Function_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/If_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
}
13 changes: 12 additions & 1 deletion lib/PhpParser/Node/Stmt/Namespace_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/TryCatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
}
9 changes: 8 additions & 1 deletion lib/PhpParser/Node/Stmt/While_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion test/PhpParser/Node/Stmt/ClassMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ public function testFunctionLike(): void {
]);

$this->assertTrue($method->returnsByRef());
$this->assertNull($method->getStmts());
$this->assertSame([], $method->getStmts());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikic Not sure if should be a BC break.

In Rector we use $node->stmts === null check to avoid foreach on null errors. So if this will turn into [], there is no real change.

}
}