8000 bug #46515 [PropertyInfo] Fix extracting int range type (norkunas) · symfony/symfony@7a9e4e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a9e4e9

Browse files
bug #46515 [PropertyInfo] Fix extracting int range type (norkunas)
This PR was merged into the 5.4 branch. Discussion ---------- [PropertyInfo] Fix extracting int range type | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 16dbefa [PropertyInfo] Fix extracting int range type
2 parents 38dbe68 + 16dbefa commit 7a9e4e9

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,23 @@ public function testDummyNamespaceWithProperty()
401401
$this->assertEquals('A\Property', $phpStanTypes[0]->getClassName());
402402
$this->assertEquals($phpDocTypes[0]->getClassName(), $phpStanTypes[0]->getClassName());
403403
}
404+
405+
/**
406+
* @dataProvider intRangeTypeProvider
407+
*/
408+
public function testExtractorIntRangeType(string $property, ?array $types)
409+
{
410+
$this->assertEquals($types, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\IntRangeDummy', $property));
411+
}
412+
413+
public function intRangeTypeProvider(): array
414+
{
415+
return [
416+
['a', [new Type(Type::BUILTIN_TYPE_INT)]],
417+
['b', [new Type(Type::BUILTIN_TYPE_INT, true)]],
418+
['c', [new Type(Type::BUILTIN_TYPE_INT)]],
419+
];
420+
}
404421
}
405422

406423
class PhpStanOmittedParamTagTypeDocBlock
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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\PropertyInfo\Tests\Fixtures;
13+
14+
class IntRangeDummy
15+
{
16+
/**
17+
* @var int<0, 100>
18+
*/
19+
public $a;
20+
21+
/**
22+
* @var int<min, 100>|null
23+
*/
24+
public $b;
25+
26+
/**
27+
* @var int<50, max>
28+
*/
29+
public $c;
30+
}

src/Symfony/Component/PropertyInfo/Util/PhpStanTypeHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ private function extractTypes(TypeNode $node, NameScope $nameScope): array
117117
if ($node instanceof GenericTypeNode) {
118118
[$mainType] = $this->extractTypes($node->type, $nameScope);
119119

120+
if (Type::BUILTIN_TYPE_INT === $mainType->getBuiltinType()) {
121+
return [$mainType];
122+
}
123+
120124
$collectionKeyTypes = $mainType->getCollectionKeyTypes();
121125
$collectionKeyValues = [];
122126
if (1 === \count($node->genericTypes)) {

0 commit comments

Comments
 (0)
0