From f09f22760ef1b292c3312105532c8e84e80cce19 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 27 Nov 2021 21:02:58 +0100 Subject: [PATCH] Declare namespacedName property For historical reasons, this property is used by the NameResolver (in default mode). Declare it explicitly, rather than using a doc comment. --- lib/PhpParser/Node/Const_.php | 6 +++--- lib/PhpParser/Node/Stmt/ClassLike.php | 6 +++--- lib/PhpParser/Node/Stmt/Function_.php | 6 +++--- test/PhpParser/NodeAbstractTest.php | 4 +++- test/PhpParser/NodeVisitor/NameResolverTest.php | 4 ++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/PhpParser/Node/Const_.php b/lib/PhpParser/Node/Const_.php index 789a426..b69eb16 100644 --- a/lib/PhpParser/Node/Const_.php +++ b/lib/PhpParser/Node/Const_.php @@ -4,9 +4,6 @@ namespace PhpParser\Node; use PhpParser\NodeAbstract; -/** - * @property Name $namespacedName Namespaced name (for global constants, if using NameResolver) - */ class Const_ extends NodeAbstract { /** @var Identifier Name */ @@ -14,6 +11,9 @@ class Const_ extends NodeAbstract /** @var Expr Value */ public $value; + /** @var Name Namespaced name (if using NameResolver) */ + public $namespacedName; + /** * Constructs a const node for use in class const and const statements. * diff --git a/lib/PhpParser/Node/Stmt/ClassLike.php b/lib/PhpParser/Node/Stmt/ClassLike.php index 840c4f6..6c33691 100644 --- a/lib/PhpParser/Node/Stmt/ClassLike.php +++ b/lib/PhpParser/Node/Stmt/ClassLike.php @@ -4,9 +4,6 @@ namespace PhpParser\Node\Stmt; use PhpParser\Node; -/** - * @property Node\Name $namespacedName Namespaced name (if using NameResolver) - */ abstract class ClassLike extends Node\Stmt { /** @var Node\Identifier|null Name */ @@ -16,6 +13,9 @@ abstract class ClassLike extends Node\Stmt /** @var Node\AttributeGroup[] PHP attribute groups */ public $attrGroups; + /** @var Node\Name Namespaced name (if using NameResolver) */ + public $namespacedName; + /** * @return TraitUse[] */ diff --git a/lib/PhpParser/Node/Stmt/Function_.php b/lib/PhpParser/Node/Stmt/Function_.php index 3fa24f4..abb7ee5 100644 --- a/lib/PhpParser/Node/Stmt/Function_.php +++ b/lib/PhpParser/Node/Stmt/Function_.php @@ -5,9 +5,6 @@ namespace PhpParser\Node\Stmt; use PhpParser\Node; use PhpParser\Node\FunctionLike; -/** - * @property Node\Name $namespacedName Namespaced name (if using NameResolver) - */ class Function_ extends Node\Stmt implements FunctionLike { /** @var bool Whether function returns by reference */ @@ -23,6 +20,9 @@ class Function_ extends Node\Stmt implements FunctionLike /** @var Node\AttributeGroup[] PHP attribute groups */ public $attrGroups; + /** @var Node\Name Namespaced name (if using NameResolver) */ + public $namespacedName; + /** * Constructs a function node. * diff --git a/test/PhpParser/NodeAbstractTest.php b/test/PhpParser/NodeAbstractTest.php index 9057f57..3553c4c 100644 --- a/test/PhpParser/NodeAbstractTest.php +++ b/test/PhpParser/NodeAbstractTest.php @@ -306,6 +306,7 @@ PHP; } ], "attrGroups": [], + "namespacedName": null, "attributes": { "startLine": 4, "comments": [ @@ -454,7 +455,8 @@ JSON; ] } ], - "attrGroups": [] + "attrGroups": [], + "namespacedName": null } ] JSON; diff --git a/test/PhpParser/NodeVisitor/NameResolverTest.php b/test/PhpParser/NodeVisitor/NameResolverTest.php index d14402b..b5035ce 100644 --- a/test/PhpParser/NodeVisitor/NameResolverTest.php +++ b/test/PhpParser/NodeVisitor/NameResolverTest.php @@ -353,7 +353,7 @@ EOC; $this->assertSame('NS\\C', (string) $stmts[0]->stmts[2]->namespacedName); $this->assertSame('NS\\D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); $this->assertSame('NS\\E', (string) $stmts[0]->stmts[4]->namespacedName); - $this->assertObjectNotHasAttribute('namespacedName', $stmts[0]->stmts[5]->class); + $this->assertNull($stmts[0]->stmts[5]->class->namespacedName); $this->assertSame('NS\\F', (string) $stmts[0]->stmts[6]->namespacedName); $stmts = $traverser->traverse([new Stmt\Namespace_(null, $nsStmts)]); @@ -362,7 +362,7 @@ EOC; $this->assertSame('C', (string) $stmts[0]->stmts[2]->namespacedName); $this->assertSame('D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); $this->assertSame('E', (string) $stmts[0]->stmts[4]->namespacedName); - $this->assertObjectNotHasAttribute('namespacedName', $stmts[0]->stmts[5]->class); + $this->assertNull($stmts[0]->stmts[5]->class->namespacedName); $this->assertSame('F', (string) $stmts[0]->stmts[6]->namespacedName); }