Conditions | 5 |
Paths | 7 |
Total Lines | 32 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 5.0113 |
Changes | 0 |
1 | <?php |
||
41 | function throwable_decode($json) |
||
42 | { |
||
43 | $properties = [ |
||
44 | 2 | 'message', |
|
45 | 'code', |
||
46 | 'file', |
||
47 | 'line', |
||
48 | 'trace', |
||
49 | 'class', |
||
50 | ]; |
||
51 | |||
52 | 2 | foreach ($properties as $property) { |
|
53 | 2 | if (!isset($json[$property])) { |
|
54 | 2 | throw new NotAnEncodedThrowableException($json); |
|
55 | } |
||
56 | } |
||
57 | |||
58 | 2 | array_pop($properties); |
|
59 | |||
60 | 2 | $throwable = new $json['class'](); |
|
61 | 2 | foreach ($properties as $key) { |
|
62 | 2 | if (!(new ReflectionClass($json['class']))->hasProperty($key)) { |
|
63 | continue; |
||
64 | } |
||
65 | |||
66 | 2 | $property = new ReflectionProperty($json['class'], $key); |
|
67 | 2 | $property->setAccessible(true); |
|
68 | 2 | $property->setValue($throwable, $json[$key]); |
|
69 | } |
||
70 | |||
71 | 2 | return $throwable; |
|
72 | } |
||
73 |