Skip to content

Commit 880bebe

Browse files
committed
getReflectionProperty refactor
1 parent 9786dd4 commit 880bebe

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php

+7-13
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,15 @@ protected function setAttributeValue($object, $attribute, $value, $format = null
164164
private function getReflectionProperty($classOrObject, $attribute)
165165
{
166166
$class = is_string($classOrObject) ? $classOrObject : get_class($classOrObject);
167-
168-
try {
169-
return new \ReflectionProperty($class, $attribute);
170-
} catch (\ReflectionException $e) {
171-
$class = new \ReflectionClass($class);
172-
173-
while ($parent = $class->getParentClass()) {
174-
try {
175-
return new \ReflectionProperty($parent->getName(), $attribute);
176-
} catch (\ReflectionException $e) {
177-
$class = $parent;
167+
while (true) {
168+
try {
169+
return isset($reflectionClass) ? $reflectionClass->getProperty($attribute) : new \ReflectionProperty($class, $attribute);
170+
} catch (\ReflectionException $e) {
171+
$reflectionClass = new \ReflectionClass($class);
172+
if (!$reflectionClass = $reflectionClass->getParentClass()) {
173+
throw $e;
178174
}
179175
}
180-
181-
throw $e;
182176
}
183177
}
184178
}

0 commit comments

Comments
 (0)