|
2 | 2 |
|
3 | 3 | namespace PHPStan\Type\Php; |
4 | 4 |
|
5 | | -use PhpParser\Node; |
6 | 5 | use PhpParser\Node\Expr\FuncCall; |
7 | 6 | use PHPStan\Analyser\Scope; |
8 | 7 | use PHPStan\Analyser\SpecifiedTypes; |
|
14 | 13 | use PHPStan\Type\FunctionTypeSpecifyingExtension; |
15 | 14 | use PHPStan\Type\MixedType; |
16 | 15 | use function count; |
17 | | -use function explode; |
18 | | -use function ltrim; |
19 | 16 |
|
20 | 17 | class DefinedConstantTypeSpecifyingExtension implements FunctionTypeSpecifyingExtension, TypeSpecifierAwareExtension |
21 | 18 | { |
22 | 19 |
|
23 | 20 | private TypeSpecifier $typeSpecifier; |
24 | 21 |
|
| 22 | + public function __construct(private ConstantHelper $constantHelper) |
| 23 | + { |
| 24 | + } |
| 25 | + |
25 | 26 | public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void |
26 | 27 | { |
27 | 28 | $this->typeSpecifier = $typeSpecifier; |
@@ -53,24 +54,8 @@ public function specifyTypes( |
53 | 54 | return new SpecifiedTypes([], []); |
54 | 55 | } |
55 | 56 |
|
56 | | - $classConstParts = explode('::', $constantName->getValue()); |
57 | | - if (count($classConstParts) >= 2) { |
58 | | - $classConstName = new Node\Name\FullyQualified(ltrim($classConstParts[0], '\\')); |
59 | | - if ($classConstName->isSpecialClassName()) { |
60 | | - $classConstName = new Node\Name($classConstName->toString()); |
61 | | - } |
62 | | - $constNode = new Node\Expr\ClassConstFetch( |
63 | | - $classConstName, |
64 | | - new Node\Identifier($classConstParts[1]), |
65 | | - ); |
66 | | - } else { |
67 | | - $constNode = new Node\Expr\ConstFetch( |
68 | | - new Node\Name\FullyQualified($constantName->getValue()), |
69 | | - ); |
70 | | - } |
71 | | - |
72 | 57 | return $this->typeSpecifier->create( |
73 | | - $constNode, |
| 58 | + $this->constantHelper->createExprFromConstantName($constantName->getValue()), |
74 | 59 | new MixedType(), |
75 | 60 | $context, |
76 | 61 | false, |
|
0 commit comments