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

Appearance settings

Commit 80a81f6

Browse filesBrowse files
committed
[PropertyInfo] Handle collection in PhpStan same as PhpDoc
1 parent 4e57b84 commit 80a81f6
Copy full SHA for 80a81f6

File tree

6 files changed

+33
-1
lines changed
Filter options

6 files changed

+33
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\PropertyInfo\Tests\Extractor;
1313

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

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

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

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php
+3Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php
+5Lines 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
*/
+20Lines 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+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
13+
14+
final class DummyCollection implements \IteratorAggregate
15+
{
16+
public function getIterator(): \Traversable
17+
{
18+
return [];
19+
}
20+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Util/PhpStanTypeHelper.php
+1-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.