@@ -299,8 +299,8 @@ public function isClassReflected(string $className): bool
299299 $ this ->initialize ();
300300 }
301301 $ className = $ this ->cleanClassName ($ className );
302-
303- return array_key_exists ( $ className, $ this ->classReflectionData );
302+ /** @phpstan-ignore booleanAnd.rightAlwaysTrue (not exactly sure why this is needed) */
303+ return isset ( $ this -> classReflectionData [ $ className]) && is_array ( $ this ->classReflectionData [ $ className ] );
304304 }
305305
306306 /**
@@ -1476,7 +1476,7 @@ protected function reflectClassMethodParameter(string $className, MethodReflecti
14761476
14771477 if (
14781478 isset ($ this ->classReflectionData [$ className ][self ::DATA_CLASS_METHODS ][$ methodName ][self ::DATA_METHOD_PARAMETERS ][$ parameter ->getName ()][self ::DATA_PARAMETER_TYPE ]) &&
1479- $ this ->classReflectionData [$ className ][self ::DATA_CLASS_METHODS ][$ methodName ][self ::DATA_METHOD_PARAMETERS ][$ parameter ->getName ()][self ::DATA_PARAMETER_TYPE ] !== $ this ->cleanClassName ($ parameterAnnotation [0 ])
1479+ $ this ->classReflectionData [$ className ][self ::DATA_CLASS_METHODS ][$ methodName ][self ::DATA_METHOD_PARAMETERS ][$ parameter ->getName ()][self ::DATA_PARAMETER_TYPE ] !== $ this ->cleanTypeName ($ parameterAnnotation [0 ])
14801480 ) {
14811481 $ this ->log (' Wrong type in @param for " ' . $ method ->getName () . ':: ' . $ parameter ->getName () . '": " ' . $ parameterAnnotation [0 ] . '" ' , LogLevel::DEBUG );
14821482 }
@@ -1691,7 +1691,7 @@ protected function evaluateClassPropertyAnnotationsForSchema(ClassSchema $classS
16911691 }
16921692
16931693 if (!$ declaredType ) {
1694- throw new \ Exception ( ' Invalid type for ' . $ className . ' ::$ ' . $ propertyName , 1744046737 ) ;
1694+ return false ;
16951695 }
16961696
16971697 if ($ this ->isPropertyAnnotatedWith ($ className , $ propertyName , ORM \Id::class)) {
@@ -1927,7 +1927,7 @@ protected function convertParameterReflectionToArray(ParameterReflection $parame
19271927 }
19281928 }
19291929 if (!isset ($ parameterInformation [self ::DATA_PARAMETER_TYPE ]) && $ parameterType !== null ) {
1930- $ parameterInformation [self ::DATA_PARAMETER_TYPE ] = $ this ->cleanClassName ($ parameterType );
1930+ $ parameterInformation [self ::DATA_PARAMETER_TYPE ] = $ this ->cleanTypeName ($ parameterType );
19311931 } elseif (!isset ($ parameterInformation [self ::DATA_PARAMETER_TYPE ])) {
19321932 $ parameterInformation [self ::DATA_PARAMETER_TYPE ] = 'mixed ' ;
19331933 }
@@ -2083,17 +2083,25 @@ public function saveToCache(): void
20832083 $ this ->log (sprintf ('Updated reflection caches (%s classes). ' , count ($ this ->updatedReflectionData )));
20842084 }
20852085
2086+ /**
2087+ * Clean a given type from possibly prefixed backslash
2088+ * @return string
2089+ */
2090+ protected function cleanTypeName (string $ className ): string
2091+ {
2092+ return ltrim ($ className , '\\' );
2093+ }
2094+
20862095 /**
20872096 * Clean a given class name from possibly prefixed backslash
20882097 * @return class-string
20892098 */
20902099 protected function cleanClassName (string $ className ): string
20912100 {
2092- $ className = ltrim ($ className, '\\' );
2093- if (!class_exists ($ className )) {
2094- throw new \ Exception ( ' Invalid class ' . $ className , 1744047892 );
2101+ $ className = $ this -> cleanTypeName ($ className );
2102+ if (!class_exists ($ className ) && ! interface_exists ( $ className ) && ! trait_exists ( $ className ) && ! enum_exists ( $ className ) ) {
2103+ throw ClassLoadingForReflectionFailedException:: forClassName ( $ className , $ className );
20952104 }
2096-
20972105 return $ className ;
20982106 }
20992107
0 commit comments