BaseParser::stringifyList()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace dlindberg\BlobChunk\Parser;
6
7
use dlindberg\BlobChunk\Manager\CheckNode;
8
use dlindberg\DOMDocumentFactory\DOMDocumentFactory as Doc;
9
10
abstract class BaseParser
11
{
12
    /**
13
     * @var CheckNode
14
     */
15
    protected $manager;
16
17
    /**
18
     * @var Doc
19
     */
20
    public $doc;
21
22
    public function __construct(CheckNode $manager)
23
    {
24
        $this->manager = $manager;
25
        $this->doc = new Doc();
26
    }
27
28
    public function setDocFactory(Doc $factory): void
29
    {
30
        $this->doc = $factory;
31
    }
32
33
    protected function stringify(\DOMNode $node): string
34
    {
35
        return $this->doc->stringify($node);
36
    }
37
38
    protected function stringifyList(\DOMNodeList $nodes): array
39
    {
40
        return $this->doc->stringifyFromList($nodes);
41
    }
42
43
    protected function collect(callable $test, \DOMNode $node, \DOMDocument $carry): \DOMNodeList
44
    {
45
        if ($test($node)) {
46
            $carry->documentElement->appendChild($carry->importNode($node, true));
47
        }
48
49
        return null !== $node->nextSibling ?
50
            $this->collect($test, $node->nextSibling, $carry) : $carry->documentElement->childNodes;
51
    }
52
53
    protected function containerDOM(): \DOMDocument
54
    {
55
        $document = new \DOMDocument();
56
        $document->appendChild($document->createElement('body', ''));
57
58
        return $document;
59
    }
60
}
61