mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-29 19:37:55 +01:00
skip generic types
This commit is contained in:
parent
52014ab277
commit
b40a1514bd
@ -662,6 +662,10 @@ final class StaticTypeMapper
|
||||
return new ArrayType(new MixedType(), $genericType);
|
||||
}
|
||||
|
||||
if ($typeName === 'Traversable') {
|
||||
return new ObjectType('Traversable');
|
||||
}
|
||||
|
||||
return new IterableType(new MixedType(), $genericType);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\Type\MixedType;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
@ -129,6 +128,11 @@ PHP
|
||||
return;
|
||||
}
|
||||
|
||||
// keep generic types
|
||||
if ($varTagValueNode->type instanceof GenericTypeNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
// keep string[] etc.
|
||||
if ($this->isNonBasicArrayType($property, $varTagValueNode)) {
|
||||
return;
|
||||
@ -140,7 +144,7 @@ PHP
|
||||
|
||||
private function isNonBasicArrayType(Property $property, VarTagValueNode $varTagValueNode): bool
|
||||
{
|
||||
if (! $this->isArrayGenericTypeNode($varTagValueNode) && ! $this->isArrayTypeNode($varTagValueNode)) {
|
||||
if (! $this->isArrayTypeNode($varTagValueNode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -152,19 +156,6 @@ PHP
|
||||
return $varTypeDocString !== 'array';
|
||||
}
|
||||
|
||||
private function isArrayGenericTypeNode(VarTagValueNode $varTagValueNode): bool
|
||||
{
|
||||
if (! $varTagValueNode->type instanceof GenericTypeNode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $varTagValueNode->type->type instanceof IdentifierTypeNode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $varTagValueNode->type->type->name === 'array';
|
||||
}
|
||||
|
||||
private function isArrayTypeNode(VarTagValueNode $varTagValueNode): bool
|
||||
{
|
||||
return $varTagValueNode->type instanceof ArrayTypeNode;
|
||||
|
Loading…
x
Reference in New Issue
Block a user