Don't type hint to traits

This commit is contained in:
Tim Ward 2020-06-11 11:45:06 -04:00 committed by GitHub
parent 1b2eeb177a
commit 559216cb0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,10 +10,12 @@ use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\PHPStan\Type\ShortenedObjectType;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Rector\TypeDeclaration\ChildPopulator\ChildParamPopulator;
use Rector\TypeDeclaration\TypeInferer\ParamTypeInferer;
@ -143,6 +145,16 @@ PHP
return;
}
if ($inferedType instanceof ObjectType) {
$fqcn = $inferedType instanceof ShortenedObjectType
? $inferedType->getFullyQualifiedName()
: $inferedType->getClassName();
$reflectionClass = new \ReflectionClass($fqcn);
if ($reflectionClass->isTrait()) {
return;
}
}
$paramTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode(
$inferedType,
PHPStanStaticTypeMapper::KIND_PARAM