Conditions | 7 |
Paths | 6 |
Total Lines | 23 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 7.0283 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | 50 | public static function getPropertyValue($object, string $fieldName) |
|
20 | { |
||
21 | 50 | if (is_array($object)) { |
|
22 | 21 | return $object[$fieldName] ?? null; |
|
23 | } |
||
24 | |||
25 | /** @noinspection PhpUnhandledExceptionInspection */ |
||
26 | 30 | if (property_exists($object, $fieldName) && (new ReflectionProperty($object, $fieldName))->isPublic()) { |
|
27 | 12 | return $object->{$fieldName}; |
|
28 | } |
||
29 | |||
30 | 21 | if (isset($object->{$fieldName})) { |
|
31 | return $object->{$fieldName}; |
||
32 | } |
||
33 | |||
34 | 21 | if (method_exists($object, $fieldName)) { |
|
35 | 5 | return $object->{$fieldName}(); |
|
36 | } |
||
37 | |||
38 | 18 | if (method_exists($object, 'get'.$fieldName)) { |
|
39 | 17 | return $object->{'get'.$fieldName}(); |
|
40 | } |
||
41 | 2 | throw new RuntimeException("Field $fieldName is not exist for object ".var_export($object, true)); |
|
42 | } |
||
44 |