Skip to content

Commit

Permalink
Declare namespacedName property
Browse files Browse the repository at this point in the history
For historical reasons, this property is used by the NameResolver
(in default mode). Declare it explicitly, rather than using a doc
comment.
  • Loading branch information
nikic committed Nov 27, 2021
1 parent d4cb98a commit f09f227
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/PhpParser/Node/Const_.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

use PhpParser\NodeAbstract;

/**
* @property Name $namespacedName Namespaced name (for global constants, if using NameResolver)
*/
class Const_ extends NodeAbstract
{
/** @var Identifier Name */
public $name;
/** @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.
*
Expand Down
6 changes: 3 additions & 3 deletions lib/PhpParser/Node/Stmt/ClassLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use PhpParser\Node;

/**
* @property Node\Name $namespacedName Namespaced name (if using NameResolver)
*/
abstract class ClassLike extends Node\Stmt
{
/** @var Node\Identifier|null Name */
Expand All @@ -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[]
*/
Expand Down
6 changes: 3 additions & 3 deletions lib/PhpParser/Node/Stmt/Function_.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
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 */
Expand All @@ -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.
*
Expand Down
4 changes: 3 additions & 1 deletion test/PhpParser/NodeAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ function functionName(&$a = 0, $b = 1.0) {
}
],
"attrGroups": [],
"namespacedName": null,
"attributes": {
"startLine": 4,
"comments": [
Expand Down Expand Up @@ -454,7 +455,8 @@ function functionName(&$a = 0, $b = 1.0) {
]
}
],
"attrGroups": []
"attrGroups": [],
"namespacedName": null
}
]
JSON;
Expand Down
4 changes: 2 additions & 2 deletions test/PhpParser/NodeVisitor/NameResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public function testAddDeclarationNamespacedName() {
$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)]);
Expand All @@ -362,7 +362,7 @@ public function testAddDeclarationNamespacedName() {
$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);
}

Expand Down

0 comments on commit f09f227

Please sign in to comment.