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