From 58da676a5183a18da56a61dc5b235fe51ba99ff1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 24 Dec 2025 15:36:59 +0700 Subject: [PATCH 1/2] [TypeDeclaration] Skip class not found on ObjectTypedPropertyFromJMSSerializerAttributeTypeRector --- .../Fixture/skip_class_not_found.php.inc | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/Class_/ObjectTypedPropertyFromJMSSerializerAttributeTypeRector/Fixture/skip_class_not_found.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/Class_/ObjectTypedPropertyFromJMSSerializerAttributeTypeRector/Fixture/skip_class_not_found.php.inc b/rules-tests/TypeDeclaration/Rector/Class_/ObjectTypedPropertyFromJMSSerializerAttributeTypeRector/Fixture/skip_class_not_found.php.inc new file mode 100644 index 00000000000..37d08b15dc9 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/Class_/ObjectTypedPropertyFromJMSSerializerAttributeTypeRector/Fixture/skip_class_not_found.php.inc @@ -0,0 +1,11 @@ + Date: Wed, 24 Dec 2025 15:40:00 +0700 Subject: [PATCH 2/2] fix --- .../NodeFactory/JMSTypePropertyTypeFactory.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rules/TypeDeclaration/NodeFactory/JMSTypePropertyTypeFactory.php b/rules/TypeDeclaration/NodeFactory/JMSTypePropertyTypeFactory.php index e5d94ac1357..7a3b839277b 100644 --- a/rules/TypeDeclaration/NodeFactory/JMSTypePropertyTypeFactory.php +++ b/rules/TypeDeclaration/NodeFactory/JMSTypePropertyTypeFactory.php @@ -6,7 +6,9 @@ use PhpParser\Node; use PhpParser\Node\Identifier; +use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Property; +use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\FloatType; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; @@ -25,6 +27,7 @@ public function __construct( private StaticTypeMapper $staticTypeMapper, private PhpDocInfoFactory $phpDocInfoFactory, private VarTagRemover $varTagRemover, + private ReflectionProvider $reflectionProvider, ) { } @@ -41,7 +44,13 @@ public function createObjectTypeNode(string $typeValue): ?Node $type = new ObjectType($typeValue); } - return $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::PROPERTY); + $node = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::PROPERTY); + + if ($node instanceof FullyQualified && ! $this->reflectionProvider->hasClass($node->toString())) { + return null; + } + + return $node; } public function createScalarTypeNode(string $typeValue, Property $property): ?Node