Total Complexity | 8 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | final class PairNode extends BaseParser implements Parse |
||
8 | { |
||
9 | public function parse(\DOMElement $node): array |
||
10 | { |
||
11 | $this->manager->setPairParentNode($node); |
||
12 | |||
13 | return $this->groupPairNodes($node->firstChild); |
||
14 | } |
||
15 | |||
16 | private function groupPairNodes(\DOMNode $node, $carry = []): ?array |
||
17 | { |
||
18 | if ($this->manager->isPairSideANode($node)) { |
||
19 | $a = $this->stringify($node); |
||
20 | ['bNodes' => $b, 'currentNode' => $node] = $this->collectBNodes($node->nextSibling); |
||
21 | $carry[] = [ |
||
22 | 'a' => $a, |
||
23 | 'b' => $b, |
||
24 | ]; |
||
25 | } |
||
26 | |||
27 | return null !== $node->nextSibling ? $this->groupPairNodes($node->nextSibling, $carry) : $carry; |
||
28 | } |
||
29 | |||
30 | private function collectBNodes(?\DOMNode $node, array $nodes = []): array |
||
44 | ]; |
||
45 | } |
||
46 | } |
||
47 |