8000 [PropertyInfo] Fix wrongly detected type for non-empty-array · symfony/symfony@9468852 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9468852

Browse files
committed
[PropertyInfo] Fix wrongly detected type for non-empty-array
1 parent 0f3ef42 commit 9468852

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/Foo.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,8 @@
1616
*/
1717
class Foo
1818
{
19-
const TYPE_A = 'a';
20-
2119
/**
2220
* @var string
2321
*/
2422
public $bar;
25-
26-
/**
27-
* @var string
28-
*/
29-
public $baz;
3023
}

src/Symfony/Component/PropertyInfo/Tests/AbstractPropertyInfoExtractorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testGetLongDescription()
5959

6060
public function testGetTypes()
6161
{
62-
$this->assertEquals([new Type(Type::BUILTIN_TYPE_INT)], $this->propertyInfo->getTypes('Foo', 'baz', []));
62+
$this->assertEquals([new Type(Type::BUILTIN_TYPE_INT)], $this->propertyInfo->getTypes('Foo', 'bar', []));
6363
}
6464

6565
public function testIsReadable()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ public function unionTypesProvider(): array
369369
['d', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [new Type(Type::BUILTIN_TYPE_STRING), new Type(Type::BUILTIN_TYPE_INT)], [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [], [new Type(Type::BUILTIN_TYPE_STRING)])])]],
370370
['e', [new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class, true, [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [], [new Type(Type::BUILTIN_TYPE_STRING)])], [new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [new Type(Type::BUILTIN_TYPE_INT)], [new Type(Type::BUILTIN_TYPE_STRING, false, null, true, [], [new Type(Type::BUILTIN_TYPE_OBJECT, false, DefaultValue::class)])])]), new Type(Type::BUILTIN_TYPE_OBJECT, false, ParentDummy::class)]],
371371
['f', null],
372+
['g', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [], [new Type(Type::BUILTIN_TYPE_STRING), new Type(Type::BUILTIN_TYPE_INT)])]],
372373
];
373374
}
374375
}

src/Symfony/Component/PropertyInfo/Tests/Fixtures/DummyUnionType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ class DummyUnionType
4848
* @var self::TYPE_*|null
4949
*/
5050
public $f;
51+
52+
/**
53+
* @var non-empty-array<string|int>
54+
*/
55+
public $g;
5156
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ private function extractTypes(TypeNode $node, NameScope $nameScope): array
165165
case 'integer':
166166
return [new Type(Type::BUILTIN_TYPE_INT)];
167167
case 'list':
168+
case 'non-empty-list':
168169
return [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT))];
170+
case 'non-empty-array':
171+
return [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)];
169172
case 'mixed':
170173
return []; // mixed seems to be ignored in all other extractors
171174
case 'parent':

0 commit comments

Comments
 (0)
0