File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
rules-tests/TypeDeclaration/Rector/Class_/ObjectTypedPropertyFromJMSSerializerAttributeTypeRector/Fixture
rules/TypeDeclaration/NodeFactory Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \TypeDeclaration \Rector \Class_ \ObjectTypedPropertyFromJMSSerializerAttributeTypeRector \Fixture ;
4+
5+ use JMS \Serializer \Annotation as JMS ;
6+
7+ final class SkipClassNotFound
8+ {
9+ #[JMS \Type('SomeNonExistentClass ' )]
10+ protected $ dynamicRef ;
11+ }
Original file line number Diff line number Diff line change 66
77use PhpParser \Node ;
88use PhpParser \Node \Identifier ;
9+ use PhpParser \Node \Name \FullyQualified ;
910use PhpParser \Node \Stmt \Property ;
11+ use PHPStan \Reflection \ReflectionProvider ;
1012use PHPStan \Type \FloatType ;
1113use PHPStan \Type \MixedType ;
1214use PHPStan \Type \ObjectType ;
@@ -25,6 +27,7 @@ public function __construct(
2527 private StaticTypeMapper $ staticTypeMapper ,
2628 private PhpDocInfoFactory $ phpDocInfoFactory ,
2729 private VarTagRemover $ varTagRemover ,
30+ private ReflectionProvider $ reflectionProvider ,
2831 ) {
2932 }
3033
@@ -41,7 +44,13 @@ public function createObjectTypeNode(string $typeValue): ?Node
4144 $ type = new ObjectType ($ typeValue );
4245 }
4346
44- return $ this ->staticTypeMapper ->mapPHPStanTypeToPhpParserNode ($ type , TypeKind::PROPERTY );
47+ $ node = $ this ->staticTypeMapper ->mapPHPStanTypeToPhpParserNode ($ type , TypeKind::PROPERTY );
48+
49+ if ($ node instanceof FullyQualified && ! $ this ->reflectionProvider ->hasClass ($ node ->toString ())) {
50+ return null ;
51+ }
52+
53+ return $ node ;
4554 }
4655
4756 public function createScalarTypeNode (string $ typeValue , Property $ property ): ?Node
You can’t perform that action at this time.
0 commit comments