| Conditions | 8 |
| Paths | 14 |
| Total Lines | 38 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 17.9939 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 26 | 6 | public function build(array $data, $depth = 0, $prevKey = null) |
|
| 27 | { |
||
| 28 | 6 | $valueOutput = null; |
|
| 29 | 6 | $arrayOutput = null; |
|
| 30 | |||
| 31 | 6 | $position = 0; |
|
| 32 | 6 | foreach ($data as $key => $val) { |
|
| 33 | 6 | if (is_array($val)) { |
|
| 34 | if ($depth == 0) { |
||
| 35 | $arrayOutput .= "\n[{$key}]\n"; |
||
| 36 | } |
||
| 37 | |||
| 38 | $arrayOutput .= $this->build($val, $depth + 1, $key); |
||
| 39 | } else { |
||
| 40 | 6 | $valStr = $this->escape($val); |
|
| 41 | |||
| 42 | 6 | if ($depth > 1) { |
|
| 43 | if ($key !== $position) { |
||
| 44 | if (ctype_digit((string) $key)) { |
||
| 45 | $position = $key; |
||
| 46 | } |
||
| 47 | |||
| 48 | $valueOutput .= "{$prevKey}[{$key}] = {$valStr}\n"; |
||
| 49 | } else { |
||
| 50 | $valueOutput .= "{$prevKey}[] = {$valStr}\n"; |
||
| 51 | } |
||
| 52 | |||
| 53 | ++$position; |
||
| 54 | } else { |
||
| 55 | 6 | $valueOutput .= "{$key} = {$valStr}\n"; |
|
| 56 | } |
||
| 57 | } |
||
| 58 | 6 | } |
|
| 59 | |||
| 60 | 6 | $output = "{$valueOutput}\n{$arrayOutput}"; |
|
| 61 | |||
| 62 | 6 | return $depth ? ltrim($output) : trim($output); |
|
| 63 | } |
||
| 64 | |||
| 91 |