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