Skip to content

Commit 317a997

Browse files
committed
PropertyHookNameVisitor is no longer needed, PHP-parser comes with propertyName attribute
1 parent 947e74e commit 317a997

File tree

8 files changed

+9
-80
lines changed

8 files changed

+9
-80
lines changed

conf/config.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,6 @@ services:
320320
tags:
321321
- phpstan.parser.richParserNodeVisitor
322322

323-
-
324-
class: PHPStan\Parser\PropertyHookNameVisitor
325-
tags:
326-
- phpstan.parser.richParserNodeVisitor
327-
328323
-
329324
class: PHPStan\Node\Printer\ExprPrinter
330325

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
use PHPStan\Parser\ImmediatelyInvokedClosureVisitor;
127127
use PHPStan\Parser\LineAttributesVisitor;
128128
use PHPStan\Parser\Parser;
129-
use PHPStan\Parser\PropertyHookNameVisitor;
130129
use PHPStan\Php\PhpVersion;
131130
use PHPStan\PhpDoc\PhpDocInheritanceResolver;
132131
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
@@ -6436,7 +6435,7 @@ public function getPhpDocs(Scope $scope, Node\FunctionLike|Node\Stmt\Property $n
64366435
} elseif ($node instanceof Node\Stmt\Function_) {
64376436
$functionName = trim($scope->getNamespace() . '\\' . $node->name->name, '\\');
64386437
} elseif ($node instanceof Node\PropertyHook) {
6439-
$propertyName = $node->getAttribute(PropertyHookNameVisitor::ATTRIBUTE_NAME);
6438+
$propertyName = $node->getAttribute('propertyName');
64406439
if ($propertyName !== null) {
64416440
$functionName = sprintf('$%s::%s', $propertyName, $node->name->toString());
64426441
}

src/Parser/CleaningVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function enterNode(Node $node): ?Node
3737
}
3838

3939
if ($node instanceof Node\PropertyHook && is_array($node->body)) {
40-
$propertyName = $node->getAttribute(PropertyHookNameVisitor::ATTRIBUTE_NAME);
40+
$propertyName = $node->getAttribute('propertyName');
4141
if ($propertyName !== null) {
4242
$node->body = $this->keepVariadicsAndYields($node->body, $propertyName);
4343
return $node;

src/Parser/PropertyHookNameVisitor.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/Parser/SimpleParser.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function __construct(
1717
private NameResolver $nameResolver,
1818
private VariadicMethodsVisitor $variadicMethodsVisitor,
1919
private VariadicFunctionsVisitor $variadicFunctionsVisitor,
20-
private PropertyHookNameVisitor $propertyHookNameVisitor,
2120
)
2221
{
2322
}
@@ -53,7 +52,6 @@ public function parseString(string $sourceCode): array
5352
$nodeTraverser->addVisitor($this->nameResolver);
5453
$nodeTraverser->addVisitor($this->variadicMethodsVisitor);
5554
$nodeTraverser->addVisitor($this->variadicFunctionsVisitor);
56-
$nodeTraverser->addVisitor($this->propertyHookNameVisitor);
5755

5856
/** @var array<Node\Stmt> */
5957
return $nodeTraverser->traverse($nodes);

src/Reflection/InitializerExprContext.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionFunction;
1010
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionParameter;
1111
use PHPStan\BetterReflection\Reflection\ReflectionConstant;
12-
use PHPStan\Parser\PropertyHookNameVisitor;
1312
use PHPStan\Reflection\Php\PhpMethodFromParserNodeReflection;
1413
use PHPStan\ShouldNotHappenException;
1514
use function array_slice;
@@ -144,15 +143,15 @@ public static function fromStubParameter(
144143
} elseif ($function instanceof ClassMethod) {
145144
$functionName = $function->name->toString();
146145
} elseif ($function instanceof PropertyHook) {
147-
$propertyName = $function->getAttribute(PropertyHookNameVisitor::ATTRIBUTE_NAME);
146+
$propertyName = $function->getAttribute('propertyName');
148147
$functionName = sprintf('$%s::%s', $propertyName, $function->name->toString());
149148
}
150149

151150
$methodName = null;
152151
if ($function instanceof ClassMethod && $className !== null) {
153152
$methodName = sprintf('%s::%s', $className, $function->name->toString());
154153
} elseif ($function instanceof PropertyHook) {
155-
$propertyName = $function->getAttribute(PropertyHookNameVisitor::ATTRIBUTE_NAME);
154+
$propertyName = $function->getAttribute('propertyName');
156155
$methodName = sprintf('%s::$%s::%s', $className, $propertyName, $function->name->toString());
157156
} elseif ($function instanceof Function_ && $function->namespacedName !== null) {
158157
$methodName = $function->namespacedName->toString();

src/Type/FileTypeMapper.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Broker\AnonymousClassNameHelper;
1010
use PHPStan\File\FileHelper;
1111
use PHPStan\Parser\Parser;
12-
use PHPStan\Parser\PropertyHookNameVisitor;
1312
use PHPStan\PhpDoc\PhpDocNodeResolver;
1413
use PHPStan\PhpDoc\PhpDocStringResolver;
1514
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
@@ -281,7 +280,7 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
281280
} elseif ($node instanceof Node\Stmt\Function_) {
282281
$functionStack[] = ltrim(sprintf('%s\\%s', $namespace, $node->name->name), '\\');
283282
} elseif ($node instanceof Node\PropertyHook) {
284-
$propertyName = $node->getAttribute(PropertyHookNameVisitor::ATTRIBUTE_NAME);
283+
$propertyName = $node->getAttribute('propertyName');
285284
if ($propertyName !== null) {
286285
$functionStack[] = sprintf('$%s::%s', $propertyName, $node->name->toString());
287286
}
@@ -299,7 +298,7 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
299298

300299
return null;
301300
} elseif ($node instanceof Node\PropertyHook) {
302-
$propertyName = $node->getAttribute(PropertyHookNameVisitor::ATTRIBUTE_NAME);
301+
$propertyName = $node->getAttribute('propertyName');
303302
if ($propertyName !== null) {
304303
$docComment = GetLastDocComment::forNode($node);
305304
if ($docComment !== null) {
@@ -394,7 +393,7 @@ static function (Node $node) use (&$namespace, &$functionStack, &$classStack): v
394393

395394
array_pop($functionStack);
396395
} elseif ($node instanceof Node\PropertyHook) {
397-
$propertyName = $node->getAttribute(PropertyHookNameVisitor::ATTRIBUTE_NAME);
396+
$propertyName = $node->getAttribute('propertyName');
398397
if ($propertyName !== null) {
399398
if (count($functionStack) === 0) {
400399
throw new ShouldNotHappenException();
@@ -503,7 +502,7 @@ function (Node $node) use ($fileName, $lookForTrait, $phpDocNodeMap, &$traitFoun
503502
} elseif ($node instanceof Node\Stmt\Function_) {
504503
$functionStack[] = ltrim(sprintf('%s\\%s', $namespace, $node->name->name), '\\');
505504
} elseif ($node instanceof Node\PropertyHook) {
506-
$propertyName = $node->getAttribute(PropertyHookNameVisitor::ATTRIBUTE_NAME);
505+
$propertyName = $node->getAttribute('propertyName');
507506
if ($propertyName !== null) {
508507
$functionStack[] = sprintf('$%s::%s', $propertyName, $node->name->toString());
509508
}
@@ -742,7 +741,7 @@ static function (Node $node, $callbackResult) use (&$namespace, &$functionStack,
742741

743742
array_pop($functionStack);
744743
} elseif ($node instanceof Node\PropertyHook) {
745-
$propertyName = $node->getAttribute(PropertyHookNameVisitor::ATTRIBUTE_NAME);
744+
$propertyName = $node->getAttribute('propertyName');
746745
if ($propertyName !== null) {
747746
if (count($functionStack) === 0) {
748747
throw new ShouldNotHappenException();

tests/PHPStan/Parser/CleaningParserTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public function testParse(
7575
new NameResolver(),
7676
new VariadicMethodsVisitor(),
7777
new VariadicFunctionsVisitor(),
78-
new PropertyHookNameVisitor(),
7978
),
8079
new PhpVersion($phpVersionId),
8180
);

0 commit comments

Comments
 (0)