Skip to content

Commit a44b242

Browse files
committed
Added a few comments
1 parent 3eb2882 commit a44b242

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/PhpDocReader/PhpDocReader.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function getPropertyClass(ReflectionProperty $property)
9898

9999
// If the class name is not fully qualified (i.e. doesn't start with a \)
100100
if ($type[0] !== '\\') {
101+
// Try to resolve the FQN using the class context
101102
$resolvedType = $this->tryResolveFqn($type, $class, $property);
102103

103104
if (!$resolvedType && !$this->ignorePhpDocErrors) {
@@ -182,6 +183,7 @@ public function getParameterClass(ReflectionParameter $parameter)
182183

183184
// If the class name is not fully qualified (i.e. doesn't start with a \)
184185
if ($type[0] !== '\\') {
186+
// Try to resolve the FQN using the class context
185187
$resolvedType = $this->tryResolveFqn($type, $class, $parameter);
186188

187189
if (!$resolvedType && !$this->ignorePhpDocErrors) {
@@ -251,6 +253,7 @@ private function tryResolveFqn($type, ReflectionClass $class, Reflector $member)
251253
if (version_compare(phpversion(), '5.4.0', '<')) {
252254
return null;
253255
} else {
256+
// If all fail, try resolving through related traits
254257
return $this->tryResolveFqnInTraits($type, $class, $member);
255258
}
256259
}
@@ -269,21 +272,24 @@ private function tryResolveFqnInTraits($type, ReflectionClass $class, Reflector
269272
{
270273
/** @var ReflectionClass[] $traits */
271274
$traits = array();
272-
275+
276+
// Get traits for the class and its parents
273277
while ($class) {
274278
$traits = array_merge($traits, $class->getTraits());
275279
$class = $class->getParentClass();
276280
}
277281

278282
foreach ($traits as $trait) {
283+
// Eliminate traits that don't have the property/method/parameter
279284
if ($member instanceof ReflectionProperty && !$trait->hasProperty($member->name)) {
280285
continue;
281286
} elseif ($member instanceof ReflectionMethod && !$trait->hasMethod($member->name)) {
282287
continue;
283288
} elseif ($member instanceof ReflectionParameter && !$trait->hasMethod($member->getDeclaringFunction()->name)) {
284289
continue;
285290
}
286-
291+
292+
// Run the resolver again with the ReflectionClass instance for the trait
287293
$resolvedType = $this->tryResolveFqn($type, $trait, $member);
288294

289295
if ($resolvedType) {

0 commit comments

Comments
 (0)