Skip to content

Commit 4817cbb

Browse files
author
Alexandru Furculita
committed
Accept Collection implementations in @var tag
1 parent ec56b25 commit 4817cbb

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111
],
1212
"require": {
13+
"php": "^7.0",
1314
"squizlabs/php_codesniffer": "^3.0",
1415
"doctrine/annotations": "^1.4",
1516
"doctrine/orm": "^2.5"

src/DoctrineAnnotationCodingStandard/Types/UnqualifiedObjectType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function qualify(string $namespace = null, ImportClassMap $imports, strin
4242
$fqcn = $namespace . '\\' . $this->className;
4343
}
4444

45+
if (class_exists($fqcn) && (new \ReflectionClass($fqcn))->implementsInterface(Collection::class)) {
46+
return new CollectionType(new MixedType());
47+
}
48+
4549
if ($fqcn === Collection::class) {
4650
return new CollectionType(new MixedType());
4751
}

tests/DoctrineAnnotationCodingStandard/Helper/TypeHelperTest.php

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

33
namespace DoctrineAnnotationCodingStandardTests\Helper;
44

5+
use Doctrine\Common\Collections\ArrayCollection;
56
use DoctrineAnnotationCodingStandard\Helper\TypeHelper;
67
use DoctrineAnnotationCodingStandard\ImportClassMap;
78
use DoctrineAnnotationCodingStandard\Types\AnyObjectType;
@@ -91,6 +92,16 @@ public function testFromStringWithTypedCollection()
9192
$this->assertEquals(new CollectionType(new ObjectType('AppBundle\\Entity\\Customer')), $type);
9293
}
9394

95+
public function testFromStringWithTypedArrayCollection()
96+
{
97+
$classMap = new ImportClassMap();
98+
$classMap->add('ArrayCollection', ArrayCollection::class);
99+
$classMap->add('Customer', 'AppBundle\\Entity\\Customer');
100+
101+
$type = TypeHelper::fromString('ArrayCollection|Customer[]', null, $classMap);
102+
$this->assertEquals(new CollectionType(new ObjectType('AppBundle\\Entity\\Customer')), $type);
103+
}
104+
94105
public function testFromStringWithTypedCollectionWithSpaces()
95106
{
96107
$classMap = new ImportClassMap();

0 commit comments

Comments
 (0)