Conditions | 4 |
Paths | 5 |
Total Lines | 28 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 4 |
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 ReflectionClass($json['class']))->newInstanceWithoutConstructor(); |
|
61 | 2 | foreach ($properties as $key) { |
|
62 | 2 | $property = new ReflectionProperty($json['class'], $key); |
|
63 | 2 | $property->setAccessible(true); |
|
64 | 2 | $property->setValue($throwable, $json[$key]); |
|
65 | } |
||
66 | |||
67 | 2 | return $throwable; |
|
68 | } |
||
69 |