| 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 |
||
| 18 | 6 | public static function export($data, bool $return = false, int $level = 0): string |
|
| 19 | { |
||
| 20 | 6 | $result = ''; |
|
| 21 | 6 | if (is_array($data) && !$data) { |
|
| 22 | $result .= '[]'; |
||
| 23 | 6 | } elseif (is_array($data)) { |
|
| 24 | 4 | $needKey = array_keys($data) !== range(0, count($data) - 1); |
|
| 25 | 4 | $result .= '[' . PHP_EOL; |
|
| 26 | 4 | foreach ($data as $key => $value) { |
|
| 27 | 4 | $result .= str_repeat(' ', 4 * ($level + 1)); |
|
| 28 | 4 | if ($needKey) { |
|
| 29 | 3 | $result .= self::export($key, true, $level + 1); |
|
| 30 | 3 | $result .= ' => '; |
|
| 31 | } |
||
| 32 | |||
| 33 | 4 | $result .= self::export($value, true, $level + 1); |
|
| 34 | 4 | $result .= ',' . PHP_EOL; |
|
| 35 | } |
||
| 36 | 4 | $result .= str_repeat(' ', 4 * $level) . ']'; |
|
| 37 | } else { |
||
| 38 | 6 | $result .= var_export($data, true); |
|
| 39 | } |
||
| 40 | |||
| 41 | 6 | if (!$return) { |
|
| 42 | echo $result; |
||
| 43 | } |
||
| 44 | |||
| 45 | 6 | return $result; |
|
| 46 | } |
||
| 48 |