|
4 | 4 |
|
5 | 5 | namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; |
6 | 6 |
|
| 7 | +use phpDocumentor\Reflection\FqsenResolver; |
7 | 8 | use phpDocumentor\Reflection\PseudoTypes\ArrayShape; |
8 | 9 | use phpDocumentor\Reflection\PseudoTypes\ArrayShapeItem; |
| 10 | +use phpDocumentor\Reflection\PseudoTypes\ConstExpression; |
| 11 | +use phpDocumentor\Reflection\PseudoTypes\FloatValue; |
9 | 12 | use phpDocumentor\Reflection\PseudoTypes\IntegerRange; |
| 13 | +use phpDocumentor\Reflection\PseudoTypes\IntegerValue; |
10 | 14 | use phpDocumentor\Reflection\PseudoTypes\List_; |
| 15 | +use phpDocumentor\Reflection\PseudoTypes\StringValue; |
11 | 16 | use phpDocumentor\Reflection\Type; |
12 | 17 | use phpDocumentor\Reflection\TypeResolver; |
13 | 18 | use phpDocumentor\Reflection\Types\Array_; |
|
20 | 25 | use phpDocumentor\Reflection\Types\Intersection; |
21 | 26 | use phpDocumentor\Reflection\Types\Nullable; |
22 | 27 | use phpDocumentor\Reflection\Types\This; |
| 28 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprFloatNode; |
| 29 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode; |
| 30 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode; |
| 31 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode; |
23 | 32 | use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode; |
24 | 33 | use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode; |
25 | 34 | use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode; |
|
48 | 57 | final class TypeFactory |
49 | 58 | { |
50 | 59 | private TypeResolver $resolver; |
| 60 | + private FqsenResolver $fqsenResolver; |
51 | 61 |
|
52 | | - public function __construct(TypeResolver $resolver) |
| 62 | + public function __construct(TypeResolver $resolver, FqsenResolver $fqsenResolver) |
53 | 63 | { |
54 | 64 | $this->resolver = $resolver; |
| 65 | + $this->fqsenResolver = $fqsenResolver; |
55 | 66 | } |
56 | 67 |
|
57 | 68 | public function createType(?TypeNode $type, ?Context $context): ?Type |
@@ -82,7 +93,7 @@ public function createType(?TypeNode $type, ?Context $context): ?Type |
82 | 93 | return $this->createFromCallable($type, $context); |
83 | 94 |
|
84 | 95 | case ConstTypeNode::class: |
85 | | - return null; |
| 96 | + return $this->createFromConst($type, $context); |
86 | 97 |
|
87 | 98 | case GenericTypeNode::class: |
88 | 99 | return $this->createFromGeneric($type, $context); |
@@ -144,12 +155,12 @@ private function createFromGeneric(GenericTypeNode $type, ?Context $context): Ty |
144 | 155 |
|
145 | 156 | case 'class-string': |
146 | 157 | return new ClassString( |
147 | | - $this->createType($type->genericTypes[0], $context)->getFqsen() |
| 158 | + $this->fqsenResolver->resolve((string) $type->genericTypes[0], $context) |
148 | 159 | ); |
149 | 160 |
|
150 | 161 | case 'interface-string': |
151 | 162 | return new InterfaceString( |
152 | | - $this->createType($type->genericTypes[0], $context)->getFqsen() |
| 163 | + $this->fqsenResolver->resolve((string) $type->genericTypes[0], $context) |
153 | 164 | ); |
154 | 165 |
|
155 | 166 | case 'list': |
@@ -180,4 +191,24 @@ private function createFromCallable(CallableTypeNode $type, ?Context $context): |
180 | 191 | { |
181 | 192 | return new Callable_(); |
182 | 193 | } |
| 194 | + |
| 195 | + private function createFromConst(ConstTypeNode $type, ?Context $context): ?Type |
| 196 | + { |
| 197 | + switch (get_class($type->constExpr)) { |
| 198 | + case ConstExprIntegerNode::class: |
| 199 | + return new IntegerValue((int) $type->constExpr->value); |
| 200 | + |
| 201 | + case ConstExprFloatNode::class: |
| 202 | + return new FloatValue((float) $type->constExpr->value); |
| 203 | + |
| 204 | + case ConstExprStringNode::class: |
| 205 | + return new StringValue($type->constExpr->value); |
| 206 | + |
| 207 | + case ConstFetchNode::class: |
| 208 | + return new ConstExpression( |
| 209 | + $this->fqsenResolver->resolve($type->constExpr->className, $context), |
| 210 | + $type->constExpr->name |
| 211 | + ); |
| 212 | + } |
| 213 | + } |
183 | 214 | } |
0 commit comments