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