diff --git a/packages/TypeDeclaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php b/packages/TypeDeclaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php index a56280c1d48c..68bdec9c0de2 100644 --- a/packages/TypeDeclaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php +++ b/packages/TypeDeclaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php @@ -12,7 +12,6 @@ use PHPStan\Type\MixedType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; -use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; use Rector\RectorDefinition\RectorDefinition; @@ -131,7 +130,13 @@ private function shouldSkip(ClassMethod $classMethod): bool return false; } - return $this->isSpecificIterableType($currentPhpDocInfo); + $returnType = $currentPhpDocInfo->getReturnType(); + + if ($returnType instanceof ArrayType && $returnType->getItemType() instanceof MixedType) { + return true; + } + + return $returnType instanceof IterableType; } private function shouldSkipType(Type $newType, ClassMethod $classMethod): bool @@ -209,16 +214,4 @@ private function shouldSkipUnionType(UnionType $unionType): bool return false; } - - private function isSpecificIterableType(PhpDocInfo $currentPhpDocInfo): bool - { - if (! $currentPhpDocInfo->getReturnType() instanceof IterableType) { - return false; - } - - /** @var IterableType $iterableType */ - $iterableType = $currentPhpDocInfo->getReturnType(); - - return ! $iterableType->getItemType() instanceof MixedType; - } } diff --git a/packages/TypeDeclaration/tests/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/skip_mixed_array.php.inc b/packages/TypeDeclaration/tests/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/skip_mixed_array.php.inc new file mode 100644 index 000000000000..b8308a01005e --- /dev/null +++ b/packages/TypeDeclaration/tests/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/skip_mixed_array.php.inc @@ -0,0 +1,17 @@ + + */ + public function someDataProvider(): iterable + { + yield [42]; + yield [[42]]; + } +}