Skip to content

Commit f4cf1ee

Browse files
committed
Use TypeStringResolver directly
1 parent 1aa4bc5 commit f4cf1ee

File tree

11 files changed

+15
-33
lines changed

11 files changed

+15
-33
lines changed

src/Analyser/ConstantResolver.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace PHPStan\Analyser;
44

55
use PhpParser\Node\Name;
6+
use PHPStan\DependencyInjection\Container;
7+
use PHPStan\PhpDoc\TypeStringResolver;
68
use PHPStan\Reflection\NamespaceAnswerer;
79
use PHPStan\Reflection\ReflectionProvider;
810
use PHPStan\Reflection\ReflectionProvider\ReflectionProviderProvider;
@@ -34,7 +36,7 @@ final class ConstantResolver
3436
/**
3537
* @param string[] $dynamicConstantNames
3638
*/
37-
public function __construct(private ReflectionProviderProvider $reflectionProviderProvider, private array $dynamicConstantNames)
39+
public function __construct(private ReflectionProviderProvider $reflectionProviderProvider, private array $dynamicConstantNames, private ?Container $container)
3840
{
3941
}
4042

@@ -305,7 +307,10 @@ public function resolveConstantType(string $constantName, Type $constantType): T
305307
if ($constantType->isConstantValue()->yes()) {
306308
if (array_key_exists($constantName, $this->dynamicConstantNames)) {
307309
$phpdocTypes = $this->dynamicConstantNames[$constantName];
308-
return $this->reflectionProviderProvider->getReflectionProvider()->getSignatureMapProvider()->getTypeFromString($phpdocTypes, null);
310+
$typeStringResolver = $this->container?->getByType(TypeStringResolver::class);
311+
if ($typeStringResolver !== null) {
312+
return $typeStringResolver->resolve($phpdocTypes, new NameScope(null, [], null));
313+
}
309314
}
310315
if (in_array($constantName, $this->dynamicConstantNames, true)) {
311316
return $constantType->generalize(GeneralizePrecision::lessSpecific());
@@ -325,7 +330,10 @@ public function resolveClassConstantType(string $className, string $constantName
325330

326331
if ($constantType->isConstantValue()->yes()) {
327332
$phpdocTypes = $this->dynamicConstantNames[$lookupConstantName];
328-
return $this->getReflectionProvider()->getSignatureMapProvider()->getTypeFromString($phpdocTypes, $className);
333+
$typeStringResolver = $this->container?->getByType(TypeStringResolver::class);
334+
if ($typeStringResolver !== null) {
335+
return $typeStringResolver->resolve($phpdocTypes, new NameScope(null, [], $className));
336+
}
329337
}
330338
}
331339

src/Analyser/ConstantResolverFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function create(): ConstantResolver
2020
return new ConstantResolver(
2121
$this->reflectionProviderProvider,
2222
$this->container->getParameter('dynamicConstantNames'),
23+
$this->container,
2324
);
2425
}
2526

src/DependencyInjection/ValidateIgnoredErrorsExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function loadConfiguration(): void
6565
$reflectionProviderProvider = new DirectReflectionProviderProvider($reflectionProvider);
6666
ReflectionProviderStaticAccessor::registerInstance($reflectionProvider);
6767
PhpVersionStaticAccessor::registerInstance(new PhpVersion(PHP_VERSION_ID));
68-
$constantResolver = new ConstantResolver($reflectionProviderProvider, []);
68+
$constantResolver = new ConstantResolver($reflectionProviderProvider, [], null);
6969

7070
$phpDocParserConfig = new ParserConfig([]);
7171
$ignoredRegexValidator = new IgnoredRegexValidator(

src/Reflection/BetterReflection/BetterReflectionProvider.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,4 @@ private function resolveName(
475475
return null;
476476
}
477477

478-
public function getSignatureMapProvider(): SignatureMapProvider
479-
{
480-
return $this->signatureMapProvider;
481-
}
482-
483478
}

src/Reflection/ClassReflection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,6 @@ public function getNativeReflection(): ReflectionClass|ReflectionEnum
177177
return $this->reflection;
178178
}
179179

180-
public function getSignatureMapProvider(): SignatureMapProvider
181-
{
182-
return $this->signatureMapProvider;
183-
}
184-
185180
public function getFileName(): ?string
186181
{
187182
if (!is_bool($this->filename)) {

src/Reflection/ReflectionProvider.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
7-
use PHPStan\Reflection\SignatureMap\SignatureMapProvider;
87

98
/** @api */
109
interface ReflectionProvider
@@ -37,6 +36,4 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
3736

3837
public function resolveConstantName(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): ?string;
3938

40-
public function getSignatureMapProvider(): SignatureMapProvider;
41-
4239
}

src/Reflection/ReflectionProvider/DummyReflectionProvider.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Reflection\FunctionReflection;
1010
use PHPStan\Reflection\NamespaceAnswerer;
1111
use PHPStan\Reflection\ReflectionProvider;
12-
use PHPStan\Reflection\SignatureMap\SignatureMapProvider;
1312
use PHPStan\ShouldNotHappenException;
1413

1514
final class DummyReflectionProvider implements ReflectionProvider
@@ -70,9 +69,4 @@ public function resolveConstantName(Node\Name $nameNode, ?NamespaceAnswerer $nam
7069
return null;
7170
}
7271

73-
public function getSignatureMapProvider(): SignatureMapProvider
74-
{
75-
throw new ShouldNotHappenException();
76-
}
77-
7872
}

src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Reflection\FunctionReflection;
1010
use PHPStan\Reflection\NamespaceAnswerer;
1111
use PHPStan\Reflection\ReflectionProvider;
12-
use PHPStan\Reflection\SignatureMap\SignatureMapProvider;
1312
use function strtolower;
1413

1514
final class MemoizingReflectionProvider implements ReflectionProvider
@@ -97,9 +96,4 @@ public function resolveConstantName(Node\Name $nameNode, ?NamespaceAnswerer $nam
9796
return $this->provider->resolveConstantName($nameNode, $namespaceAnswerer);
9897
}
9998

100-
public function getSignatureMapProvider(): SignatureMapProvider
101-
{
102-
return $this->provider->getSignatureMapProvider();
103-
}
104-
10599
}

src/Reflection/SignatureMap/SignatureMapParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getFunctionSignature(array $map, ?string $className): FunctionSi
4646
);
4747
}
4848

49-
public function getTypeFromString(string $typeString, ?string $className): Type
49+
private function getTypeFromString(string $typeString, ?string $className): Type
5050
{
5151
if ($typeString === '') {
5252
return new MixedType(true);

src/Reflection/SignatureMap/SignatureMapProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ public function hasClassConstantMetadata(string $className, string $constantName
4040
*/
4141
public function getClassConstantMetadata(string $className, string $constantName): array;
4242

43-
public function getTypeFromString(string $typeString, ?string $className): Type;
44-
4543
}

0 commit comments

Comments
 (0)