Skip to content

Commit 8d09ba8

Browse files
committed
Support PropertyHooks in NameResolver
1 parent 23c79fb commit 8d09ba8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/PhpParser/NodeVisitor/NameResolver.php

+6
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ public function enterNode(Node $node) {
110110
$node->type = $this->resolveType($node->type);
111111
}
112112
$this->resolveAttrGroups($node);
113+
} elseif ($node instanceof Node\PropertyHook) {
114+
foreach ($node->params as $param) {
115+
$param->type = $this->resolveType($param->type);
116+
$this->resolveAttrGroups($param);
117+
}
118+
$this->resolveAttrGroups($node);
113119
} elseif ($node instanceof Stmt\Const_) {
114120
foreach ($node->consts as $const) {
115121
$this->addNamespacedName($const);

test/PhpParser/NodeVisitor/NameResolverTest.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ class A extends B implements C, D {
201201
public const X A = X::Bar;
202202
public const X\Foo B = X\Foo::Bar;
203203
public const \X\Foo C = \X\Foo::Bar;
204+
205+
public Foo $foo {
206+
#[X]
207+
set(#[X] Bar $v) {}
208+
}
209+
210+
public function __construct(
211+
public Foo $bar {
212+
#[X]
213+
set(#[X] Bar $v) {}
214+
}
215+
) {}
204216
}
205217
206218
#[X]
@@ -269,6 +281,18 @@ class A extends \NS\B implements \NS\C, \NS\D
269281
public const \NS\X A = \NS\X::Bar;
270282
public const \NS\X\Foo B = \NS\X\Foo::Bar;
271283
public const \X\Foo C = \X\Foo::Bar;
284+
public \NS\Foo $foo {
285+
#[\NS\X]
286+
set(#[\NS\X] \NS\Bar $v) {
287+
}
288+
}
289+
public function __construct(public \NS\Foo $bar {
290+
#[\NS\X]
291+
set(#[\NS\X] \NS\Bar $v) {
292+
}
293+
})
294+
{
295+
}
272296
}
273297
#[\NS\X]
274298
interface A extends \NS\C, \NS\D
@@ -543,7 +567,7 @@ public function testAttributeOnlyMode(): void {
543567
}
544568

545569
private function parseAndResolve(string $code): array {
546-
$parser = new PhpParser\Parser\Php7(new PhpParser\Lexer\Emulative());
570+
$parser = new PhpParser\Parser\Php8(new PhpParser\Lexer\Emulative());
547571
$traverser = new PhpParser\NodeTraverser();
548572
$traverser->addVisitor(new NameResolver());
549573

0 commit comments

Comments
 (0)