Skip to content

Commit a3992cb

Browse files
Idrinthsebastianbergmann
authored andcommitted
removing need for additional conditional block
1 parent 57c4368 commit a3992cb

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/Framework/Assert.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,30 +2351,23 @@ public static function getObjectAttribute($object, string $attributeName)
23512351
}
23522352

23532353
try {
2354-
$attribute = new ReflectionProperty($object, $attributeName);
2355-
} catch (ReflectionException $e) {
23562354
$reflector = new ReflectionObject($object);
2357-
2358-
while ($reflector = $reflector->getParentClass()) {
2355+
do {
23592356
try {
23602357
$attribute = $reflector->getProperty($attributeName);
2358+
if (!$attribute || $attribute->isPublic()) {
2359+
return $object->$attributeName;
2360+
}
2361+
2362+
$attribute->setAccessible(true);
2363+
$value = $attribute->getValue($object);
2364+
$attribute->setAccessible(false);
23612365

2362-
break;
2366+
return $value;
23632367
} catch (ReflectionException $e) {
23642368
}
2365-
}
2366-
}
2367-
2368-
if (isset($attribute)) {
2369-
if (!$attribute || $attribute->isPublic()) {
2370-
return $object->$attributeName;
2371-
}
2372-
2373-
$attribute->setAccessible(true);
2374-
$value = $attribute->getValue($object);
2375-
$attribute->setAccessible(false);
2376-
2377-
return $value;
2369+
} while ($reflector = $reflector->getParentClass());
2370+
} catch (ReflectionException $e) {
23782371
}
23792372

23802373
throw new Exception(

0 commit comments

Comments
 (0)