Conditions | 6 |
Paths | 10 |
Total Lines | 24 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
12 | protected function toSimpleXML( |
||
13 | array $input, |
||
14 | SimpleXMLElement $parent, |
||
15 | bool $alreadySingularized = false |
||
16 | ): void { |
||
17 | foreach ($input as $key => $value) { |
||
18 | |||
19 | if (is_numeric($key)) { |
||
20 | $name = $alreadySingularized ? |
||
21 | 'item' : $this->singularizer->convert($parent->getName()); |
||
22 | $singularized = true; |
||
23 | } else { |
||
24 | $name = str_replace(['<', '>'], '', (string) $key); |
||
25 | $singularized = false; |
||
26 | } |
||
27 | |||
28 | if (is_array($value)) { |
||
29 | $node = $parent->addChild($name); |
||
30 | $this->toSimpleXML($value, $node, $singularized); |
||
31 | } elseif ($singularized) { |
||
32 | $child = $parent->addChild($name); |
||
33 | $child->addAttribute('value', (string) $value); |
||
34 | } else { |
||
35 | $parent->addAttribute($name, (string) $value); |
||
36 | } |
||
41 |