Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;

final class SkipMixedArray
{
/**
* @return mixed[]
*/
public function someMethod(): array
Comment thread
gnutix marked this conversation as resolved.
{
return [
42,
[42],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;

final class SkipMixedIterable
{
/**
* @return iterable<mixed>
*/
public function someDataProvider(): iterable
{
yield [42];
yield [[42]];
}
}