| Conditions | 8 |
| Paths | 6 |
| Total Lines | 25 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | private static function normalizeObject(object $object): mixed |
||
| 45 | { |
||
| 46 | if ($object instanceof DateTime || $object instanceof DateTimeInterface) { |
||
| 47 | return $object->format(DateTimeInterface::ATOM); |
||
| 48 | } |
||
| 49 | |||
| 50 | // Handle enums |
||
| 51 | if (method_exists($object, 'name') && method_exists($object, 'cases')) { |
||
| 52 | if (method_exists($object, 'value')) { |
||
| 53 | return $object->value; |
||
| 54 | } |
||
| 55 | |||
| 56 | return $object->name; |
||
| 57 | } |
||
| 58 | |||
| 59 | // Try to convert object to array |
||
| 60 | if (method_exists($object, 'toArray')) { |
||
| 61 | return self::normalize($object->toArray()); |
||
| 62 | } |
||
| 63 | |||
| 64 | if (method_exists($object, 'jsonSerialize')) { |
||
| 65 | return self::normalize($object->jsonSerialize()); |
||
| 66 | } |
||
| 67 | |||
| 68 | return json_decode(json_encode($object, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR); |
||
| 69 | } |
||
| 72 |