diff --git a/src/Constraint/Typehint/PhpDocParser.php b/src/Constraint/Typehint/PhpDocParser.php index 569902d..d187731 100644 --- a/src/Constraint/Typehint/PhpDocParser.php +++ b/src/Constraint/Typehint/PhpDocParser.php @@ -41,7 +41,8 @@ public function getReturnTypehint(string $originalDocComment): ?string return null; } - $docComment = preg_replace('/array<(.*?),\s(.*?)>/', 'array<$1,$2>', $docComment); + // Convert array to array + $docComment = preg_replace('/(\w+)<(.*?),\s(.*?)>/', '$1<$2,$3>', $docComment); if ($docComment === null) { return null; // @codeCoverageIgnore } diff --git a/tests/Integration/data/success/Regular/Types/CompoundTypes/IterableTypedFullProperty.php b/tests/Integration/data/success/Regular/Types/CompoundTypes/IterableTypedFullProperty.php new file mode 100644 index 0000000..7804841 --- /dev/null +++ b/tests/Integration/data/success/Regular/Types/CompoundTypes/IterableTypedFullProperty.php @@ -0,0 +1,28 @@ + */ + private $property = false; + + /** + * @return iterable + */ + public function getProperty(): iterable + { + return $this->property; + } + + /** + * @param iterable $property + */ + public function setProperty(iterable $property): self + { + $this->property = $property; + + return $this; + } +} diff --git a/tests/Unit/Constraint/Typehint/data/All/DocComment/IteratorTypedFull.php b/tests/Unit/Constraint/Typehint/data/All/DocComment/IteratorTypedFull.php new file mode 100644 index 0000000..3133f14 --- /dev/null +++ b/tests/Unit/Constraint/Typehint/data/All/DocComment/IteratorTypedFull.php @@ -0,0 +1,29 @@ + $param + * + * @return ArrayIterator + */ + public function testMethod(ArrayIterator $param): ArrayIterator + { + return $param; + } + + public function getExpectedType(): Type + { + return new Collection(new Fqsen('\\' . ArrayIterator::class), new String_(), new String_()); + } +}