mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 20:39:43 +01:00
[AddArrayReturnDocTypeRector] Allow mixed[] and iterable<mixed>… (#2630)
[AddArrayReturnDocTypeRector] Allow mixed[] and iterable<mixed> in place of Rector's setting wrong infered types
This commit is contained in:
commit
35cbc9f36a
@ -12,7 +12,6 @@ use PHPStan\Type\IterableType;
|
||||
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 @@ PHP
|
||||
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 @@ PHP
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
|
||||
|
||||
final class SkipMixedArray
|
||||
{
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function someMethod(): array
|
||||
{
|
||||
return [
|
||||
42,
|
||||
[42],
|
||||
];
|
||||
}
|
||||
}
|
@ -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]];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user