8000 [TypeInfo] Fix handling ConstFetchNode · symfony/symfony@38d6ac6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 38d6ac6

Browse files
committed
[TypeInfo] Fix handling ConstFetchNode
1 parent fa4d2d8 commit 38d6ac6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
13+
14+
final class DummyWithConstants
15+
{
16+
public const DUMMY_A = 'a';
17+
public const DUMMY_B = 'b';
18+
public const DUMMY_C = 'c';
19+
}

src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyBackedEnum;
2020
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyCollection;
2121
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyEnum;
22+
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithConstants;
2223
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithTemplates;
2324
use Symfony\Component\TypeInfo\Type;
2425
use Symfony\Component\TypeInfo\TypeContext\TypeContext;
@@ -89,6 +90,7 @@ public static function resolveDataProvider(): iterable
8990
yield [Type::null(), 'null'];
9091
yield [Type::string(), '"string"'];
9192
yield [Type::true(), 'true'];
93+
yield [Type::string(), DummyWithConstants::class.'::DUMMY_*'];
9294

9395
// identifiers
9496
yield [Type::bool(), 'bool'];

src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNullNode;
1919
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
2020
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprTrueNode;
21+
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
2122
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
2223
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
2324
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
@@ -125,7 +126,8 @@ private function getTypeFromNode(TypeNode $node, ?TypeContext $typeContext): Typ
125126
ConstExprFloatNode::class => Type::float(),
126127
ConstExprIntegerNode::class => Type::int(),
127128
ConstExprNullNode::class => Type::null(),
128-
ConstExprStringNode::class => Type::string(),
129+
ConstExprStringNode::class,
130+
ConstFetchNode::class => Type::string(),
129131
ConstExprTrueNode::class => Type::true(),
130132
default => throw new \DomainException(\sprintf('Unhandled "%s" constant expression.', $node->constExpr::class)),
131133
};

0 commit comments

Comments
 (0)
0