dlindberg /
BlobChunk
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace dlindberg\BlobChunk\Parser; |
||||
| 6 | |||||
| 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 |
||||
| 31 | { |
||||
| 32 | if ($this->manager->isPairSideBNode($node)) { |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 33 | $nodes[] = $this->stringify($node); |
||||
|
0 ignored issues
–
show
It seems like
$node can also be of type null; however, parameter $node of dlindberg\BlobChunk\Parser\BaseParser::stringify() does only seem to accept DOMNode, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 34 | } |
||||
| 35 | if ($this->manager->isPairSideANode($node)) { |
||||
|
0 ignored issues
–
show
It seems like
$node can also be of type null; however, parameter $input of dlindberg\BlobChunk\Mana...Node::isPairSideANode() does only seem to accept DOMNode, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 36 | $node = $node->previousSibling; |
||||
| 37 | } elseif (null !== $node->nextSibling) { |
||||
| 38 | return $this->collectBNodes($node->nextSibling, $nodes); |
||||
| 39 | } |
||||
| 40 | |||||
| 41 | return [ |
||||
| 42 | 'currentNode' => $node, |
||||
| 43 | 'bNodes' => $nodes, |
||||
| 44 | ]; |
||||
| 45 | } |
||||
| 46 | } |
||||
| 47 |