@@ -71,7 +71,11 @@ public function parseAnnotationType(string $rawType, \ReflectionClass $reflClass
7171 */
7272 public function parseReflectionType (\ReflectionType $ reflType ): PropertyType
7373 {
74- return $ this ->createType ($ reflType ->getName (), $ reflType ->allowsNull ());
74+ if ($ reflType instanceof \ReflectionNamedType) {
75+ return $ this ->createType ($ reflType ->getName (), $ reflType ->allowsNull ());
76+ }
77+
78+ throw new InvalidTypeException (sprintf ('No type information found, got %s but expected %s ' , \ReflectionType::class, \ReflectionNamedType::class));
7579 }
7680
7781 private function createType (string $ rawType , bool $ nullable , \ReflectionClass $ reflClass = null ): PropertyType
@@ -118,9 +122,20 @@ private function resolveClass(string $className, \ReflectionClass $reflClass = n
118122 if (null !== $ reflClass ) {
119123 // resolve use statements of the class with the type information
120124 $ lowerClassName = strtolower ($ className );
121- $ imports = $ this ->useStatementsParser ->parseClass ($ reflClass );
122- if (isset ($ imports [$ lowerClassName ])) {
123- return $ imports [$ lowerClassName ];
125+
126+ $ reflCurrentClass = $ reflClass ;
127+ do {
128+ $ imports = $ this ->useStatementsParser ->parseClass ($ reflCurrentClass );
129+ if (isset ($ imports [$ lowerClassName ])) {
130+ return $ imports [$ lowerClassName ];
131+ }
132+ } while (false !== ($ reflCurrentClass = $ reflCurrentClass ->getParentClass ()));
133+
134+ foreach ($ reflClass ->getTraits () as $ reflTrait ) {
135+ $ imports = $ this ->useStatementsParser ->parseClass ($ reflTrait );
136+ if (isset ($ imports [$ lowerClassName ])) {
137+ return $ imports [$ lowerClassName ];
138+ }
124139 }
125140
126141 // the referenced class is expected to be in the same namespace
0 commit comments