|
21 | 21 | use PHPStan\PhpDocParser\Parser\PhpDocParser;
|
22 | 22 | use PHPStan\PhpDocParser\Parser\TokenIterator;
|
23 | 23 | use PHPStan\PhpDocParser\Parser\TypeParser;
|
| 24 | +use Symfony\Component\PropertyInfo\PhpStan\NameScope; |
24 | 25 | use Symfony\Component\PropertyInfo\PhpStan\NameScopeFactory;
|
25 | 26 | use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
|
26 | 27 | use Symfony\Component\PropertyInfo\Type as LegacyType;
|
@@ -55,6 +56,9 @@ final class PhpStanExtractor implements PropertyTypeExtractorInterface, Construc
|
55 | 56 | private array $accessorPrefixes;
|
56 | 57 | private array $arrayMutatorPrefixes;
|
57 | 58 |
|
| 59 | + /** @var array<string, NameScope> */ |
| 60 | + private array $contexts = []; |
| 61 | + |
58 | 62 | /**
|
59 | 63 | * @param list<string>|null $mutatorPrefixes
|
60 | 64 | * @param list<string>|null $accessorPrefixes
|
@@ -86,7 +90,6 @@ public function getTypes(string $class, string $property, array $context = []):
|
86 | 90 | {
|
87 | 91 | /** @var PhpDocNode|null $docNode */
|
88 | 92 | [$docNode, $source, $prefix, $declaringClass] = $this->getDocBlock($class, $property);
|
89 |
| - $nameScope = $this->nameScopeFactory->create($class, $declaringClass); |
90 | 93 | if (null === $docNode) {
|
91 | 94 | return null;
|
92 | 95 | }
|
@@ -120,6 +123,7 @@ public function getTypes(string $class, string $property, array $context = []):
|
120 | 123 | continue;
|
121 | 124 | }
|
122 | 125 |
|
| 126 | + $nameScope ??= $this->contexts[$class.'/'.$declaringClass] ??= $this->nameScopeFactory->create($class, $declaringClass); |
123 | 127 | foreach ($this->phpStanTypeHelper->getTypes($tagDocNode->value, $nameScope) as $type) {
|
124 | 128 | switch ($type->getClassName()) {
|
125 | 129 | case 'self':
|
|
0 commit comments