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.
This commit is contained in:
Nikita Popov 2021-11-27 21:02:58 +01:00
parent d4cb98ae38
commit f09f22760e
5 changed files with 14 additions and 12 deletions

View File

@ -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.
*

View File

@ -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[]
*/

View File

@ -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.
*

View File

@ -306,6 +306,7 @@ PHP;
}
],
"attrGroups": [],
"namespacedName": null,
"attributes": {
"startLine": 4,
"comments": [
@ -454,7 +455,8 @@ JSON;
]
}
],
"attrGroups": []
"attrGroups": [],
"namespacedName": null
}
]
JSON;

View File

@ -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);
}