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

Skip to content

Commit 6e237a9

Browse files
committed
[TypeInfo] Fix handling ConstFetchNode
1 parent fa4d2d8 commit 6e237a9

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ public static function unionTypesProvider(): iterable
927927
Type::object(ParentDummy::class),
928928
Type::null(),
929929
)];
930-
yield ['f', null];
930+
yield ['f', Type::union(Type::string(), Type::int(), Type::float(), Type::bool(), Type::null())];
931931
yield ['g', Type::array(Type::union(Type::string(), Type::int()))];
932932
}
933933

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 8000 +
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;
@@ -136,6 +137,7 @@ public static function resolveDataProvider(): iterable
136137
yield [Type::union(Type::int(), Type::float(), Type::string(), Type::bool()), 'scalar'];
137138
yield [Type::union(Type::int(), Type::float()), 'number'];
138139
yield [Type::union(Type::int(), Type::float(), Type::string()), 'numeric'];
140+
yield [Type::union(Type::string(), Type::int(), Type::float(), Type::bool(), Type::null()), DummyWithConstants::class.'::DUMMY_*'];
139141
yield [Type::object(AbstractDummy::class), 'self', $typeContextFactory->createFromClassName(Dummy::class, AbstractDummy::class)];
140142
yield [Type::object(Dummy::class), 'static', $typeContextFactory->createFromClassName(Dummy::class, AbstractDummy::class)];
141143
yield [Type::object(AbstractDummy::class), 'parent', $typeContextFactory->createFromClassName(Dummy::class)];

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

Lines changed: 2 additions & 0 deletions
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;
@@ -127,6 +128,7 @@ private function getTypeFromNode(TypeNode $node, ?TypeContext $typeContext): Typ
127128
ConstExprNullNode::class => Type::null(),
128129
ConstExprStringNode::class => Type::string(),
129130
ConstExprTrueNode::class => Type::true(),
131+
ConstFetchNode::class => Type::union(Type::string(), Type::int(), Type::float(), Type::bool(), Type::null()),
130132
default => throw new \DomainException(\sprintf('Unhandled "%s" constant expression.', $node->constExpr::class)),
131133
};
132134
}

0 commit comments

Comments
 (0)
0