Passed
Push — master ( 0d07bf...dd4616 )
by Steve
35s
created

BodyNode::copyTree()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * (c) Steve Nebes <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace SN\DaisyDiff\Html\Dom;
12
13
/**
14
 * Represents the root of a HTML document.
15
 */
16
class BodyNode extends TagNode
17
{
18
    /**
19
     * Default values.
20
     */
21 71
    public function __construct()
22
    {
23 71
        parent::__construct(null, 'body');
24 71
    }
25
26
    /**
27
     * @return Node
28
     */
29 2
    public function copyTree(): Node
30
    {
31 2
        $newThis = new static();
32
33
        /** @var Node $child */
34 2
        foreach ($this->getIterator() as $child) {
35 1
            $newChild = $child->copyTree();
36 1
            $newChild->setParent($newThis);
37 1
            $newThis->addChild($newChild);
38
        }
39
40 2
        return $newThis;
41
    }
42
43
    /**
44
     * @param int $id
45
     * @return Node[]
46
     */
47 11
    public function getMinimalDeletedSet(int $id): array
48
    {
49 11
        $nodes = [];
50
51 11
        foreach ($this->getIterator() as $child) {
52 9
            $childrenChildren = $child->getMinimalDeletedSet($id);
53 9
            $nodes = \array_merge($nodes, $childrenChildren);
54
        }
55
56 11
        return $nodes;
57
    }
58
}
59