| Conditions | 8 |
| Paths | 14 |
| Total Lines | 30 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 8 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 40 | 14 | private static function toArrayWithDepth(mixed $data, int $limit, int $depth): mixed |
|
| 41 | { |
||
| 42 | 14 | if ($limit <= 0) { |
|
| 43 | 2 | throw new UnexpectedValueException('Limit value should be positive number'); |
|
| 44 | } |
||
| 45 | |||
| 46 | 12 | if ($depth > $limit) { |
|
| 47 | 2 | return $data; |
|
| 48 | } |
||
| 49 | |||
| 50 | 12 | if ($data instanceof Arrayable) { |
|
| 51 | 3 | $data = $data->__toArray(); |
|
| 52 | 12 | } elseif ($data instanceof stdClass) { |
|
| 53 | 2 | $data = (array) $data; |
|
| 54 | } |
||
| 55 | |||
| 56 | 12 | if (is_iterable($data)) { |
|
| 57 | 11 | $arrayData = []; |
|
| 58 | 11 | foreach ($data as $k => $v) { |
|
| 59 | 11 | $arrayData[$k] = self::toArrayWithDepth($v, $limit, $depth + 1); |
|
| 60 | } |
||
| 61 | |||
| 62 | 11 | return $arrayData; |
|
| 63 | } |
||
| 64 | |||
| 65 | 11 | if ($depth === 1) { |
|
| 66 | 1 | throw new RuntimeException('Cannot cast to array'); |
|
| 67 | } |
||
| 68 | |||
| 69 | 10 | return $data; |
|
| 70 | } |
||
| 72 |