| Conditions | 3 |
| Paths | 4 |
| Total Lines | 15 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 38 | 4 | public function convert($records, int $options = 0): string |
|
| 39 | { |
||
| 40 | 4 | $options = $this->filterMinRange($options, 0, 'The options must be a positive integer or 0'); |
|
| 41 | 4 | $records = $this->filterIterable($records); |
|
| 42 | 4 | if (!is_array($records)) { |
|
| 43 | 4 | $records = iterator_to_array($records); |
|
| 44 | } |
||
| 45 | |||
| 46 | 4 | $json = @json_encode($records, $options, 2); |
|
| 47 | 4 | if (JSON_ERROR_NONE === json_last_error()) { |
|
| 48 | 2 | return $json; |
|
| 49 | } |
||
| 50 | |||
| 51 | 2 | throw new RuntimeException(json_last_error_msg()); |
|
| 52 | } |
||
| 53 | } |
||
| 54 |