Skip to content

Commit

Permalink
removing need for additional conditional block
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrinth authored and sebastianbergmann committed Jul 6, 2018
1 parent 57c4368 commit a3992cb
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -2351,30 +2351,23 @@ public static function getObjectAttribute($object, string $attributeName)
}

try {
$attribute = new ReflectionProperty($object, $attributeName);
} catch (ReflectionException $e) {
$reflector = new ReflectionObject($object);

while ($reflector = $reflector->getParentClass()) {
do {
try {
$attribute = $reflector->getProperty($attributeName);
if (!$attribute || $attribute->isPublic()) {
return $object->$attributeName;
}

$attribute->setAccessible(true);
$value = $attribute->getValue($object);
$attribute->setAccessible(false);

break;
return $value;
} catch (ReflectionException $e) {
}
}
}

if (isset($attribute)) {
if (!$attribute || $attribute->isPublic()) {
return $object->$attributeName;
}

$attribute->setAccessible(true);
$value = $attribute->getValue($object);
$attribute->setAccessible(false);

return $value;
} while ($reflector = $reflector->getParentClass());
} catch (ReflectionException $e) {
}

throw new Exception(
Expand Down

0 comments on commit a3992cb

Please sign in to comment.