Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Node] add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors #836

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
rebase
  • Loading branch information
TomasVotruba committed Sep 25, 2022
commit 6ee11bd98408a6f0cf03a5bb20c2bed77fd6df22
5 changes: 0 additions & 5 deletions lib/PhpParser/Internal/PrintableNewAnonClassNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
*
* @internal
*/
<<<<<<< HEAD
class PrintableNewAnonClassNode extends Expr {
=======
class PrintableNewAnonClassNode extends Expr implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
/** @var Node\AttributeGroup[] PHP attribute groups */
public $attrGroups;
/** @var Node\Arg[] Arguments */
Expand Down
7 changes: 1 addition & 6 deletions lib/PhpParser/Node/Expr/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
use PhpParser\Node\Expr;
use PhpParser\Node\FunctionLike;

<<<<<<< HEAD
class Closure extends Expr implements FunctionLike {
=======
class Closure extends Expr implements FunctionLike, Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class Closure extends Expr implements FunctionLike, Node\StmtsIterable {
/** @var bool Whether the closure is static */
public $static;
/** @var bool Whether to return by reference */
Expand Down
11 changes: 1 addition & 10 deletions lib/PhpParser/Node/Stmt/Case_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class Case_ extends Node\Stmt {
=======
class Case_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class Case_ extends Node\Stmt implements Node\StmtsIterable {
/** @var null|Node\Expr Condition (null for default) */
public $cond;
/** @var Node\Stmt[] Statements */
Expand All @@ -32,11 +27,7 @@ public function getSubNodeNames(): array {
return ['cond', 'stmts'];
}

<<<<<<< HEAD
public function getType(): string {
=======
public function getType() : string {
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
return 'Stmt_Case';
}
}
7 changes: 1 addition & 6 deletions lib/PhpParser/Node/Stmt/Catch_.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr;

<<<<<<< HEAD
class Catch_ extends Node\Stmt {
=======
class Catch_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
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 */
Expand Down
7 changes: 1 addition & 6 deletions lib/PhpParser/Node/Stmt/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
use PhpParser\Node;
use PhpParser\Node\FunctionLike;

<<<<<<< HEAD
class ClassMethod extends Node\Stmt implements FunctionLike {
=======
class ClassMethod extends Node\Stmt implements FunctionLike, Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
/** @var int Flags */
public $flags;
/** @var bool Whether to return by reference */
Expand All @@ -22,7 +17,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike, Node\StmtsIterable
public $params;
/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */
public $returnType;
/** @var Node\Stmt[] Statements */
/** @var Node\Stmt[]|null Statements */
public $stmts;
/** @var Node\AttributeGroup[] PHP attribute groups */
public $attrGroups;
Expand Down
11 changes: 1 addition & 10 deletions lib/PhpParser/Node/Stmt/Do_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class Do_ extends Node\Stmt {
=======
class Do_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class Do_ extends Node\Stmt implements Node\StmtsIterable {
/** @var Node\Stmt[] Statements */
public $stmts;
/** @var Node\Expr Condition */
Expand All @@ -32,11 +27,7 @@ public function getSubNodeNames(): array {
return ['stmts', 'cond'];
}

<<<<<<< HEAD
public function getType(): string {
=======
public function getType() : string {
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
return 'Stmt_Do';
}
}
11 changes: 1 addition & 10 deletions lib/PhpParser/Node/Stmt/ElseIf_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class ElseIf_ extends Node\Stmt {
=======
class ElseIf_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class ElseIf_ extends Node\Stmt implements Node\StmtsIterable {
/** @var Node\Expr Condition */
public $cond;
/** @var Node\Stmt[] Statements */
Expand All @@ -32,11 +27,7 @@ public function getSubNodeNames(): array {
return ['cond', 'stmts'];
}

<<<<<<< HEAD
public function getType(): string {
=======
public function getType() : string {
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
return 'Stmt_ElseIf';
}
}
11 changes: 1 addition & 10 deletions lib/PhpParser/Node/Stmt/Else_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class Else_ extends Node\Stmt {
=======
class Else_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class Else_ extends Node\Stmt implements Node\StmtsIterable {
/** @var Node\Stmt[] Statements */
public $stmts;

Expand All @@ -28,11 +23,7 @@ public function getSubNodeNames(): array {
return ['stmts'];
}

<<<<<<< HEAD
public function getType(): string {
=======
public function getType() : string {
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
return 'Stmt_Else';
}
}
11 changes: 1 addition & 10 deletions lib/PhpParser/Node/Stmt/Finally_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class Finally_ extends Node\Stmt {
=======
class Finally_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class Finally_ extends Node\Stmt implements Node\StmtsIterable {
/** @var Node\Stmt[] Statements */
public $stmts;

Expand All @@ -28,11 +23,7 @@ public function getSubNodeNames(): array {
return ['stmts'];
}

<<<<<<< HEAD
public function getType(): string {
=======
public function getType() : string {
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
return 'Stmt_Finally';
}
}
11 changes: 1 addition & 10 deletions lib/PhpParser/Node/Stmt/For_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class For_ extends Node\Stmt {
=======
class For_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class For_ extends Node\Stmt implements Node\StmtsIterable {
/** @var Node\Expr[] Init expressions */
public $init;
/** @var Node\Expr[] Loop conditions */
Expand Down Expand Up @@ -41,11 +36,7 @@ public function getSubNodeNames(): array {
return ['init', 'cond', 'loop', 'stmts'];
}

<<<<<<< HEAD
public function getType(): string {
=======
public function getType() : string {
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
return 'Stmt_For';
}
}
11 changes: 1 addition & 10 deletions lib/PhpParser/Node/Stmt/Foreach_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class Foreach_ extends Node\Stmt {
=======
class Foreach_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
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 */
Expand Down Expand Up @@ -45,11 +40,7 @@ public function getSubNodeNames(): array {
return ['expr', 'keyVar', 'byRef', 'valueVar', 'stmts'];
}

<<<<<<< HEAD
public function getType(): string {
=======
public function getType() : string {
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
return 'Stmt_Foreach';
}
}
7 changes: 1 addition & 6 deletions lib/PhpParser/Node/Stmt/Function_.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
use PhpParser\Node;
use PhpParser\Node\FunctionLike;

<<<<<<< HEAD
class Function_ extends Node\Stmt implements FunctionLike {
=======
class Function_ extends Node\Stmt implements FunctionLike, Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class Function_ extends Node\Stmt implements FunctionLike, Node\StmtsIterable {
/** @var bool Whether function returns by reference */
public $byRef;
/** @var Node\Identifier Name */
Expand Down
11 changes: 1 addition & 10 deletions lib/PhpParser/Node/Stmt/If_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class If_ extends Node\Stmt {
=======
class If_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class If_ extends Node\Stmt implements Node\StmtsIterable {
/** @var Node\Expr Condition expression */
public $cond;
/** @var Node\Stmt[] Statements */
Expand Down Expand Up @@ -41,11 +36,7 @@ public function getSubNodeNames(): array {
return ['cond', 'stmts', 'elseifs', 'else'];
}

<<<<<<< HEAD
public function getType(): string {
=======
public function getType() : string {
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
return 'Stmt_If';
}
}
11 changes: 1 addition & 10 deletions lib/PhpParser/Node/Stmt/Namespace_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class Namespace_ extends Node\Stmt {
=======
class Namespace_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class Namespace_ extends Node\Stmt implements Node\StmtsIterable {
/* For use in the "kind" attribute */
public const KIND_SEMICOLON = 1;
public const KIND_BRACED = 2;
Expand All @@ -36,11 +31,7 @@ public function getSubNodeNames(): array {
return ['name', 'stmts'];
}

<<<<<<< HEAD
public function getType(): string {
=======
public function getType() : string {
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
return 'Stmt_Namespace';
}
}
7 changes: 1 addition & 6 deletions lib/PhpParser/Node/Stmt/TryCatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class TryCatch extends Node\Stmt {
=======
class TryCatch extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class TryCatch extends Node\Stmt implements Node\StmtsIterable {
/** @var Node\Stmt[] Statements */
public $stmts;
/** @var Catch_[] Catches */
Expand Down
11 changes: 1 addition & 10 deletions lib/PhpParser/Node/Stmt/While_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

use PhpParser\Node;

<<<<<<< HEAD
class While_ extends Node\Stmt {
=======
class While_ extends Node\Stmt implements Node\StmtsIterable
{
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
class While_ extends Node\Stmt implements Node\StmtsIterable {
/** @var Node\Expr Condition */
public $cond;
/** @var Node\Stmt[] Statements */
Expand All @@ -32,11 +27,7 @@ public function getSubNodeNames(): array {
return ['cond', 'stmts'];
}

<<<<<<< HEAD
public function getType(): string {
=======
public function getType() : string {
>>>>>>> 920aae4f (add StmtsIterable interface to mark nodes that contain iterable stmts to improve hooking in node visitors)
return 'Stmt_While';
}
}
8 changes: 4 additions & 4 deletions test/PhpParser/Node/StmtsIterableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use PhpParser\NodeFinder;
use PhpParser\ParserFactory;

class StmtsIterableTest extends \PHPUnit\Framework\TestCase
final class StmtsIterableTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
$parser = (new ParserFactory())->createForNewestSupportedVersion();
$nodes = $parser->parse(<<<'CODE_SAMPLE'
<?php

Expand All @@ -29,7 +29,7 @@ function clearItemList($items)
$stmtsIterables = $nodeFinder->findInstanceOf($nodes, StmtsIterable::class);

$this->assertCount(2, $stmtsIterables);
$this->assertInstanceOf(Function_::class, $stmtsIterables[0]);
$this->assertInstanceOf(Foreach_::class, $stmtsIterables[1]);
// $this->assertInstanceOf(Function_::class, $stmtsIterables[0]);
// $this->assertInstanceOf(Foreach_::class, $stmtsIterables[1]);
}
}