Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit80a81f6

Browse files
committed
[PropertyInfo] Handle collection in PhpStan same as PhpDoc
1 parent4e57b84 commit80a81f6

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

‎src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Component\PropertyInfo\Tests\Extractor;
1313

14+
useSymfony\Component\PropertyInfo\Tests\Fixtures\DummyCollection;
1415
usephpDocumentor\Reflection\DocBlock\StandardTagFactory;
1516
usephpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
1617
usephpDocumentor\Reflection\Types\Collection;
@@ -160,6 +161,7 @@ public static function typesProvider()
160161
null,
161162
],
162163
['self', [newType(Type::BUILTIN_TYPE_OBJECT,false, Dummy::class)],null,null],
164+
['collectionAsObject', [newType(Type::BUILTIN_TYPE_OBJECT,false, DummyCollection::class,true, [newType(Type::BUILTIN_TYPE_INT)], [newType(Type::BUILTIN_TYPE_STRING)])],null,null],
163165
];
164166
}
165167

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
useSymfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummyWithoutDocBlock;
1818
useSymfony\Component\PropertyInfo\Tests\Fixtures\DefaultValue;
1919
useSymfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
20+
useSymfony\Component\PropertyInfo\Tests\Fixtures\DummyCollection;
2021
useSymfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
2122
useSymfony\Component\PropertyInfo\Tests\Fixtures\RootDummy\RootDummyItem;
2223
useSymfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\AnotherNamespace\DummyInAnotherNamespace;
@@ -130,6 +131,7 @@ public static function typesProvider()
130131
['self', [newType(Type::BUILTIN_TYPE_OBJECT,false, Dummy::class)]],
131132
['rootDummyItems', [newType(Type::BUILTIN_TYPE_ARRAY,false,null,true,newType(Type::BUILTIN_TYPE_INT),newType(Type::BUILTIN_TYPE_OBJECT,false, RootDummyItem::class))]],
132133
['rootDummyItem', [newType(Type::BUILTIN_TYPE_OBJECT,false, RootDummyItem::class)]],
134+
['collectionAsObject', [newType(Type::BUILTIN_TYPE_OBJECT,false, DummyCollection::class,true, [newType(Type::BUILTIN_TYPE_INT)], [newType(Type::BUILTIN_TYPE_STRING)])]],
133135
];
134136
}
135137

‎src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function testGetProperties()
5353
'bal',
5454
'parent',
5555
'collection',
56+
'collectionAsObject',
5657
'nestedCollection',
5758
'mixedCollection',
5859
'B',
@@ -118,6 +119,7 @@ public function testGetPropertiesWithCustomPrefixes()
118119
'bal',
119120
'parent',
120121
'collection',
122+
'collectionAsObject',
121123
'nestedCollection',
122124
'mixedCollection',
123125
'B',
@@ -172,6 +174,7 @@ public function testGetPropertiesWithNoPrefixes()
172174
'bal',
173175
'parent',
174176
'collection',
177+
'collectionAsObject',
175178
'nestedCollection',
176179
'mixedCollection',
177180
'B',

‎src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class Dummy extends ParentDummy
4646
*/
4747
public$collection;
4848

49+
/**
50+
* @var DummyCollection<int, string>
51+
*/
52+
public$collectionAsObject;
53+
4954
/**
5055
* @var string[][]
5156
*/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
namespaceSymfony\Component\PropertyInfo\Tests\Fixtures;
13+
14+
finalclass DummyCollectionimplements \IteratorAggregate
15+
{
16+
publicfunctiongetIterator():\Traversable
17+
{
18+
return [];
19+
}
20+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private function extractTypes(TypeNode $node, NameScope $nameScope): array
121121
return [$mainType];
122122
}
123123

124-
$collection =$mainType->isCollection() ||\in_array($mainType->getClassName(),[\Traversable::class,\Iterator::class, \IteratorAggregate::class, \ArrayAccess::class, \Generator::class],true);
124+
$collection =$mainType->isCollection() ||\is_a($mainType->getClassName(), \Traversable::class,true) ||\is_a($mainType->getClassName(), \ArrayAccess::class,true);
125125

126126
// it's safer to fall back to other extractors if the generic type is too abstract
127127
if (!$collection && !class_exists($mainType->getClassName())) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp