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

Commit55fc9bf

Browse files
committed
[TypeInfo] Handle collection types properly
1 parenta2d03c5 commit55fc9bf

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespaceSymfony\Component\TypeInfo\Tests\Fixtures;
4+
5+
finalclass DummyCollectionimplements \IteratorAggregate
6+
{
7+
publicfunctiongetIterator():\Traversable
8+
{
9+
return [];
10+
}
11+
}

‎src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
useSymfony\Component\TypeInfo\Exception\UnsupportedException;
1717
useSymfony\Component\TypeInfo\Tests\Fixtures\AbstractDummy;
1818
useSymfony\Component\TypeInfo\Tests\Fixtures\Dummy;
19+
useSymfony\Component\TypeInfo\Tests\Fixtures\DummyCollection;
1920
useSymfony\Component\TypeInfo\Tests\Fixtures\DummyWithTemplates;
2021
useSymfony\Component\TypeInfo\Type;
2122
useSymfony\Component\TypeInfo\TypeContext\TypeContext;
@@ -150,6 +151,7 @@ public function resolveDataProvider(): iterable
150151
yield [Type::collection(Type::object(\IteratorAggregate::class)), \IteratorAggregate::class];
151152
yield [Type::collection(Type::object(\IteratorAggregate::class), Type::string()), \IteratorAggregate::class.'<string>'];
152153
yield [Type::collection(Type::object(\IteratorAggregate::class), Type::bool(), Type::string()), \IteratorAggregate::class.'<string, bool>'];
154+
yield [Type::collection(Type::object(DummyCollection::class), Type::bool(), Type::string()), DummyCollection::class.'<string, bool>'];
153155
}
154156

155157
publicfunctiontestCannotResolveNonStringType()

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@
5353
*/
5454
finalclass StringTypeResolverimplements TypeResolverInterface
5555
{
56-
privateconstCOLLECTION_CLASS_NAMES = [\Traversable::class, \Iterator::class, \IteratorAggregate::class, \ArrayAccess::class, \Generator::class];
57-
5856
/**
5957
* @var array<string, bool>
6058
*/
@@ -164,7 +162,7 @@ private function getTypeFromNode(TypeNode $node, ?TypeContext $typeContext): Typ
164162
default =>$this->resolveCustomIdentifier($node->name,$typeContext),
165163
};
166164

167-
if ($typeinstanceof ObjectType &&\in_array($type->getClassName(),self::COLLECTION_CLASS_NAMES,true)) {
165+
if ($typeinstanceof ObjectType &&(\is_a($type->getClassName(),\Traversable::class,true) ||\is_a($type->getClassName(), \ArrayAccess::class,true))) {
168166
return Type::collection($type);
169167
}
170168

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp