Conditions | 2 |
Paths | 2 |
Total Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
15 | public static function parse(array $expression, $removeNumericIndex = true, $indent = 4): string |
||
16 | { |
||
17 | $object = json_decode(str_replace(['(', ')'], ['(', ')'], json_encode($expression)), true); |
||
18 | $export = str_replace(['array (', ')', '(', ')'], ['[', ']', '(', ')'], var_export($object, true)); |
||
19 | $export = preg_replace("/ => \n[^\S\n]*\[/m", ' => [', $export); |
||
20 | $export = preg_replace("/ => \[\n[^\S\n]*\]/m", ' => []', $export); |
||
21 | $spaces = str_repeat(' ', $indent); |
||
22 | $export = preg_replace("/([ ]{2})(?![^ ])/m", $spaces, $export); |
||
23 | $export = preg_replace("/^([ ]{2})/m", $spaces, $export); |
||
24 | |||
25 | if ($removeNumericIndex) { |
||
26 | $export = preg_replace("/([0-9]+) => /m", '', $export); |
||
27 | } |
||
28 | |||
29 | return $export; |
||
30 | } |
||
31 | } |
||
32 |