diff --git a/rules/TypedCollections/DocBlockAnalyzer/CollectionTagValueNodeAnalyzer.php b/rules/TypedCollections/DocBlockAnalyzer/CollectionTagValueNodeAnalyzer.php index 9e663df8..46e00f61 100644 --- a/rules/TypedCollections/DocBlockAnalyzer/CollectionTagValueNodeAnalyzer.php +++ b/rules/TypedCollections/DocBlockAnalyzer/CollectionTagValueNodeAnalyzer.php @@ -23,10 +23,11 @@ public function detect(ParamTagValueNode|ReturnTagValueNode $tagValueNode): bool return false; } - if ($genericTypeNode->type->name === 'Collection') { + $name = ltrim($genericTypeNode->type->name, '\\'); + if ($name === 'Collection') { return true; } - return $genericTypeNode->type->name === DoctrineClass::COLLECTION; + return $name === DoctrineClass::COLLECTION; } } diff --git a/rules/TypedCollections/DocBlockProcessor/UnionCollectionTagValueNodeNarrower.php b/rules/TypedCollections/DocBlockProcessor/UnionCollectionTagValueNodeNarrower.php index e8022b98..5ea715f5 100644 --- a/rules/TypedCollections/DocBlockProcessor/UnionCollectionTagValueNodeNarrower.php +++ b/rules/TypedCollections/DocBlockProcessor/UnionCollectionTagValueNodeNarrower.php @@ -216,7 +216,7 @@ private function isCollectionIdentifierTypeNode(TypeNode $typeNode): bool } return in_array( - $typeNode->name, + ltrim($typeNode->name, '\\'), [DoctrineClass::COLLECTION, DoctrineClass::ARRAY_COLLECTION, 'Collection', 'ArrayCollection'], true ); diff --git a/tests/Set/TypedCollectionsWithoutImportNames/Fixture/param_type_position.php.inc b/tests/Set/TypedCollectionsWithoutImportNames/Fixture/param_type_position.php.inc new file mode 100644 index 00000000..648c30ce --- /dev/null +++ b/tests/Set/TypedCollectionsWithoutImportNames/Fixture/param_type_position.php.inc @@ -0,0 +1,51 @@ +collection as $item) { + $this->items[] = $item; + } + } +} + +?> +----- + $collection + */ + public function __construct( + private readonly DocumentManager $documentManager, + private \Doctrine\Common\Collections\Collection $collection + ) { + foreach ($this->collection as $item) { + $this->items[] = $item; + } + } +} + +?> diff --git a/tests/Set/TypedCollectionsWithoutImportNames/Fixture/remove_nullable_on_param_array.php.inc b/tests/Set/TypedCollectionsWithoutImportNames/Fixture/remove_nullable_on_param_array.php.inc new file mode 100644 index 00000000..d1410dfb --- /dev/null +++ b/tests/Set/TypedCollectionsWithoutImportNames/Fixture/remove_nullable_on_param_array.php.inc @@ -0,0 +1,43 @@ + +----- + $items + */ + public function handleAllocations(int $counter, \Doctrine\Common\Collections\Collection $items): void + { + foreach ($items as $item) { + } + } +} + +?> diff --git a/tests/Set/TypedCollectionsWithoutImportNames/TypedCollectionsWithoutImportNamesTest.php b/tests/Set/TypedCollectionsWithoutImportNames/TypedCollectionsWithoutImportNamesTest.php new file mode 100644 index 00000000..974bb840 --- /dev/null +++ b/tests/Set/TypedCollectionsWithoutImportNames/TypedCollectionsWithoutImportNamesTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_set.php'; + } +} diff --git a/tests/Set/TypedCollectionsWithoutImportNames/config/configured_set.php b/tests/Set/TypedCollectionsWithoutImportNames/config/configured_set.php new file mode 100644 index 00000000..eefec28f --- /dev/null +++ b/tests/Set/TypedCollectionsWithoutImportNames/config/configured_set.php @@ -0,0 +1,12 @@ +sets([__DIR__ . '/../../../../config/sets/typed-collections.php']); + + $rectorConfig->phpVersion(PhpVersion::PHP_84); +};