skip generic types

This commit is contained in:
TomasVotruba 2019-12-30 19:00:15 +01:00
parent 52014ab277
commit b40a1514bd
2 changed files with 10 additions and 15 deletions

View File

@ -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);
}
}

View File

@ -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;