diff --git a/functionMap.php b/functionMap.php index 6396809..1692e4f 100644 --- a/functionMap.php +++ b/functionMap.php @@ -21,6 +21,14 @@ * * '' => [null, '' => ''] * + * For class methods: + * + * '' => ['', '' => ''] + * + * For class properties: + * + * '' => [null, '@phpstan-var' => ''] + * * @link https://github.com/phpstan/phpstan-src/blob/1.10.x/resources/functionMap.php */ return [ diff --git a/src/Visitor.php b/src/Visitor.php index f2bb20d..aa0aea1 100644 --- a/src/Visitor.php +++ b/src/Visitor.php @@ -76,15 +76,16 @@ public function enterNode(Node $node) $symbolName = self::getNodeName($node); - if ($node instanceof ClassMethod) { + if ($node instanceof ClassMethod || $node instanceof Property) { $parent = $this->stack[count($this->stack) - 2]; \assert($parent instanceof \PhpParser\Node\Stmt\ClassLike); if ($parent->name !== null) { $symbolName = sprintf( - '%1$s::%2$s', + '%1$s::%2$s%3$s', $parent->name->name, - $node->name->name + $node instanceof Property ? '$' : '', + $symbolName ); } } @@ -125,10 +126,7 @@ private static function getNodeName(Node $node): string } if ($node instanceof Property) { - return sprintf( - 'property_%s', - uniqid() - ); + return $node->props[0]->name->name; } return '';