55
66use PhpParser \Node ;
77use PhpParser \Node \Identifier ;
8+ use PhpParser \Node \Name \FullyQualified ;
89use PhpParser \Node \Stmt \Property ;
10+ use PHPStan \Reflection \ReflectionProvider ;
911use PHPStan \Type \FloatType ;
1012use PHPStan \Type \MixedType ;
1113use PHPStan \Type \ObjectType ;
@@ -34,12 +36,17 @@ final class JMSTypePropertyTypeFactory
3436 * @readonly
3537 */
3638 private VarTagRemover $ varTagRemover ;
37- public function __construct (ScalarStringToTypeMapper $ scalarStringToTypeMapper , StaticTypeMapper $ staticTypeMapper , PhpDocInfoFactory $ phpDocInfoFactory , VarTagRemover $ varTagRemover )
39+ /**
40+ * @readonly
41+ */
42+ private ReflectionProvider $ reflectionProvider ;
43+ public function __construct (ScalarStringToTypeMapper $ scalarStringToTypeMapper , StaticTypeMapper $ staticTypeMapper , PhpDocInfoFactory $ phpDocInfoFactory , VarTagRemover $ varTagRemover , ReflectionProvider $ reflectionProvider )
3844 {
3945 $ this ->scalarStringToTypeMapper = $ scalarStringToTypeMapper ;
4046 $ this ->staticTypeMapper = $ staticTypeMapper ;
4147 $ this ->phpDocInfoFactory = $ phpDocInfoFactory ;
4248 $ this ->varTagRemover = $ varTagRemover ;
49+ $ this ->reflectionProvider = $ reflectionProvider ;
4350 }
4451 public function createObjectTypeNode (string $ typeValue ): ?Node
4552 {
@@ -52,7 +59,11 @@ public function createObjectTypeNode(string $typeValue): ?Node
5259 // fallback to object type
5360 $ type = new ObjectType ($ typeValue );
5461 }
55- return $ this ->staticTypeMapper ->mapPHPStanTypeToPhpParserNode ($ type , TypeKind::PROPERTY );
62+ $ node = $ this ->staticTypeMapper ->mapPHPStanTypeToPhpParserNode ($ type , TypeKind::PROPERTY );
63+ if ($ node instanceof FullyQualified && !$ this ->reflectionProvider ->hasClass ($ node ->toString ())) {
64+ return null ;
65+ }
66+ return $ node ;
5667 }
5768 public function createScalarTypeNode (string $ typeValue , Property $ property ): ?Node
5869 {
0 commit comments