| Conditions | 5 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 6 |
| CRAP Score | 5.9256 |
| Changes | 0 | ||
| 1 | <?php |
||
| 38 | 37 | protected function jsonToArray(string $content = null): ?array |
|
| 39 | { |
||
| 40 | 37 | if (empty($content)) { |
|
| 41 | return null; |
||
| 42 | } |
||
| 43 | |||
| 44 | 37 | if (false === strpos($this->headers->get('Content-Type'), 'json')) { |
|
| 45 | throw new InvalidParameterException('The content returned must be in a JSON format.'); |
||
| 46 | } |
||
| 47 | |||
| 48 | 37 | $data = @json_decode($content, true); |
|
| 49 | 37 | if ($data === null && json_last_error() !== JSON_ERROR_NONE) { |
|
| 50 | throw new \RuntimeException('It was not possible to convert the current content to JSON.'); |
||
| 51 | } |
||
| 52 | |||
| 53 | 37 | return $data; |
|
| 54 | } |
||
| 56 |