diff --git a/rules-tests/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector/Fixture/type_from_use.php.inc b/rules-tests/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector/Fixture/type_from_use.php.inc new file mode 100644 index 00000000000..10f131b3de8 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector/Fixture/type_from_use.php.inc @@ -0,0 +1,30 @@ + +----- + diff --git a/rules/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector.php b/rules/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector.php index 98497205f83..8635014d3b0 100644 --- a/rules/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector.php +++ b/rules/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector.php @@ -4,6 +4,7 @@ namespace Rector\TypeDeclaration\Rector\Class_; +use PHPStan\Type\TypeWithClassName; use PhpParser\Node; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; @@ -13,7 +14,6 @@ use Rector\Comments\NodeDocBlock\DocBlockUpdater; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -92,7 +92,10 @@ public function refactor(Node $node): ?Node } $varType = $phpDocInfo->getVarType(); - if ($varType instanceof FullyQualifiedObjectType && $varType->getClassName() === 'DateTimeInterface') { + $className = $varType instanceof TypeWithClassName + ? $this->nodeTypeResolver->getFullyQualifiedClassName($varType) + : null; + if ($className === 'DateTimeInterface') { $phpDocInfo->removeByType(VarTagValueNode::class); $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property);