Conditions | 7 |
Paths | 6 |
Total Lines | 28 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 7.0572 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | 6 | public static function export(mixed $data, bool $return = false, int $level = 0): string |
|
17 | { |
||
18 | 6 | $result = ''; |
|
19 | 6 | if (is_array($data) && !$data) { |
|
20 | $result .= '[]'; |
||
21 | 6 | } elseif (is_array($data)) { |
|
22 | 4 | $needKey = !array_is_list($data); |
|
23 | 4 | $result .= '[' . PHP_EOL; |
|
24 | 4 | foreach ($data as $key => $value) { |
|
25 | 4 | $result .= str_repeat(' ', 4 * ($level + 1)); |
|
26 | 4 | if ($needKey) { |
|
27 | 3 | $result .= self::export($key, true, $level + 1); |
|
28 | 3 | $result .= ' => '; |
|
29 | } |
||
30 | |||
31 | 4 | $result .= self::export($value, true, $level + 1); |
|
32 | 4 | $result .= ',' . PHP_EOL; |
|
33 | } |
||
34 | 4 | $result .= str_repeat(' ', 4 * $level) . ']'; |
|
35 | } else { |
||
36 | 6 | $result .= var_export($data, true); |
|
37 | } |
||
38 | |||
39 | 6 | if (!$return) { |
|
40 | echo $result; |
||
41 | } |
||
42 | |||
43 | 6 | return $result; |
|
44 | } |
||
46 |