@@ -98,6 +98,7 @@ public function getPropertyClass(ReflectionProperty $property)
98
98
99
99
// If the class name is not fully qualified (i.e. doesn't start with a \)
100
100
if ($ type [0 ] !== '\\' ) {
101
+ // Try to resolve the FQN using the class context
101
102
$ resolvedType = $ this ->tryResolveFqn ($ type , $ class , $ property );
102
103
103
104
if (!$ resolvedType && !$ this ->ignorePhpDocErrors ) {
@@ -182,6 +183,7 @@ public function getParameterClass(ReflectionParameter $parameter)
182
183
183
184
// If the class name is not fully qualified (i.e. doesn't start with a \)
184
185
if ($ type [0 ] !== '\\' ) {
186
+ // Try to resolve the FQN using the class context
185
187
$ resolvedType = $ this ->tryResolveFqn ($ type , $ class , $ parameter );
186
188
187
189
if (!$ resolvedType && !$ this ->ignorePhpDocErrors ) {
@@ -251,6 +253,7 @@ private function tryResolveFqn($type, ReflectionClass $class, Reflector $member)
251
253
if (version_compare (phpversion (), '5.4.0 ' , '< ' )) {
252
254
return null ;
253
255
} else {
256
+ // If all fail, try resolving through related traits
254
257
return $ this ->tryResolveFqnInTraits ($ type , $ class , $ member );
255
258
}
256
259
}
@@ -269,21 +272,24 @@ private function tryResolveFqnInTraits($type, ReflectionClass $class, Reflector
269
272
{
270
273
/** @var ReflectionClass[] $traits */
271
274
$ traits = array ();
272
-
275
+
276
+ // Get traits for the class and its parents
273
277
while ($ class ) {
274
278
$ traits = array_merge ($ traits , $ class ->getTraits ());
275
279
$ class = $ class ->getParentClass ();
276
280
}
277
281
278
282
foreach ($ traits as $ trait ) {
283
+ // Eliminate traits that don't have the property/method/parameter
279
284
if ($ member instanceof ReflectionProperty && !$ trait ->hasProperty ($ member ->name )) {
280
285
continue ;
281
286
} elseif ($ member instanceof ReflectionMethod && !$ trait ->hasMethod ($ member ->name )) {
282
287
continue ;
283
288
} elseif ($ member instanceof ReflectionParameter && !$ trait ->hasMethod ($ member ->getDeclaringFunction ()->name )) {
284
289
continue ;
285
290
}
286
-
291
+
292
+ // Run the resolver again with the ReflectionClass instance for the trait
287
293
$ resolvedType = $ this ->tryResolveFqn ($ type , $ trait , $ member );
288
294
289
295
if ($ resolvedType ) {
0 commit comments