Document   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 48
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A replaceNode() 0 19 3
A getNodes() 0 3 1
A appendNode() 0 5 1
A prependNode() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file was originally part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
11
 *  - (c) John MacFarlane
12
 *
13
 * For the full copyright and license information, please view the LICENSE
14
 * file that was distributed with this source code.
15
 */
16
17
namespace League\Emoji\Node;
18
19
class Document
20
{
21
    /** @var array<int, Node> */
22
    protected $nodes = [];
23
24 249
    public function appendNode(Node $node): void
25
    {
26 249
        $node->setDocument($this);
27
28 249
        $this->nodes[] = $node;
29 249
    }
30
31
    /**
32
     * @return Node[]
33
     */
34 255
    public function &getNodes(): array
35
    {
36 255
        return $this->nodes;
37
    }
38
39 3
    public function prependNode(Node $node): void
40
    {
41 3
        $node->setDocument($this);
42
43 3
        \array_unshift($this->nodes, $node);
44
45 3
        $this->nodes = \array_values($this->nodes);
46 3
    }
47
48 24
    public function replaceNode(Node $oldNode, ?Node $newNode = null): void
49
    {
50 24
        $index = \array_search($oldNode, $this->nodes, true);
51
52 24
        if ($index === false) {
53 3
            return;
54
        }
55
56 24
        $replacement = [];
57
58 24
        if ($newNode !== null) {
59 24
            $oldNode->setDocument();
60 24
            $newNode->setDocument($this);
61 24
            $replacement[] = $newNode;
62
        }
63
64 24
        \array_splice($this->nodes, /** @scrutinizer ignore-type */ $index, 1, $replacement);
65
66 24
        $this->nodes = \array_values($this->nodes);
67 24
    }
68
}
69