| Conditions | 6 |
| Paths | 8 |
| Total Lines | 32 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | 1 | public function add(NodeInterface ...$nodes): NodeInterface |
|
| 20 | { |
||
| 21 | 1 | foreach ($nodes as $node) { |
|
| 22 | 1 | if (0 === $this->count()) { |
|
| 23 | 1 | parent::add($node); |
|
| 24 | |||
| 25 | 1 | continue; |
|
| 26 | } |
||
| 27 | |||
| 28 | 1 | $count = []; |
|
| 29 | |||
| 30 | 1 | foreach ($this->children() as $child) { |
|
| 31 | 1 | $count[$child->count()] = $child; |
|
| 32 | } |
||
| 33 | |||
| 34 | 1 | $keys = array_keys($count); |
|
| 35 | 1 | $keys[] = 0; |
|
| 36 | |||
| 37 | 1 | if (min($keys) === max($keys)) { |
|
| 38 | 1 | parent::add($node); |
|
| 39 | |||
| 40 | 1 | continue; |
|
| 41 | } |
||
| 42 | |||
| 43 | 1 | ksort($count); |
|
| 44 | |||
| 45 | 1 | if (null !== $child = array_shift($count)) { |
|
| 46 | 1 | $child->add($node); |
|
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | 1 | return $this; |
|
| 51 | } |
||
| 53 |