| Conditions | 5 |
| Paths | 5 |
| Total Lines | 28 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | public function export($value, int $indentationLevel = 0) : string |
||
| 26 | { |
||
| 27 | if (! is_array($value)) { |
||
| 28 | return var_export($value, true); |
||
| 29 | } |
||
| 30 | |||
| 31 | $indentation = str_repeat(self::INDENTATION, $indentationLevel); |
||
| 32 | $longestKey = array_reduce(array_keys($value), static function ($k, $v) { |
||
| 33 | return (string) (strlen((string) $k) > strlen((string) $v) ? $k : $v); |
||
| 34 | }); |
||
| 35 | $maxKeyLength = strlen($longestKey) + (is_numeric($longestKey) ? 0 : 2); |
||
| 36 | |||
| 37 | $lines = []; |
||
| 38 | |||
| 39 | $lines[] = $indentation . '['; |
||
| 40 | |||
| 41 | foreach ($value as $entryKey => $entryValue) { |
||
| 42 | $lines[] = sprintf( |
||
| 43 | '%s%s => %s,', |
||
| 44 | $indentation . self::INDENTATION, |
||
| 45 | str_pad(var_export($entryKey, true), $maxKeyLength), |
||
| 46 | ltrim($this->export($entryValue, $indentationLevel + 1)) |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | |||
| 50 | $lines[] = $indentation . ']'; |
||
| 51 | |||
| 52 | return implode(PHP_EOL, $lines); |
||
| 53 | } |
||
| 55 |