Conditions | 6 |
Paths | 8 |
Total Lines | 30 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
13 | function convert_exception_to_array($e) |
||
14 | { |
||
15 | if (PHP_VERSION_ID < 70000) { |
||
16 | |||
17 | if (!($e instanceof \Exception)) { |
||
18 | |||
19 | throw new \Exception('input must be instance of Exception'); |
||
20 | } |
||
21 | } else { |
||
22 | |||
23 | if (!($e instanceof \Throwable)) { |
||
24 | |||
25 | throw new \Exception('input must be instance of Throwable'); |
||
26 | } |
||
27 | } |
||
28 | |||
29 | $destination = new \stdClass(); |
||
30 | $destination->class = get_class($e); |
||
31 | foreach ((new \ReflectionObject($e))->getProperties() as $sourceProperty) { |
||
32 | |||
33 | if (!in_array($sourceProperty->name, ['messages', 'severity', 'xdebug_message'])) { |
||
34 | |||
35 | $sourceProperty->setAccessible(true); |
||
36 | $destination->{$sourceProperty->getName()} = $sourceProperty->getValue($e); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | // return exception |
||
41 | return (array)$destination; |
||
42 | } |
||
43 | } |
||
44 |