AttributeNode::setAttributes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types=1);
9
10
namespace loophp\phptree\Node;
11
12
use loophp\phptree\Traverser\TraverserInterface;
13
14
class AttributeNode extends NaryNode implements AttributeNodeInterface
15
{
16
    /**
17
     * @var array
18
     */
19
    private $attributes;
20
21
    /**
22
     * ValueNode constructor.
23
     *
24
     * @param array<int|string, mixed> $attributes
25
     */
26 10
    public function __construct(
27
        array $attributes = [],
28
        int $capacity = 0,
29
        ?TraverserInterface $traverser = null,
30
        ?NodeInterface $parent = null
31
    ) {
32 10
        parent::__construct($capacity, $traverser, $parent);
33
34 10
        $this->attributes = $attributes;
35 10
    }
36
37 4
    public function getAttribute(string $key)
38
    {
39 4
        return $this->getAttributes()[$key] ?? null;
40
    }
41
42 4
    public function getAttributes(): array
43
    {
44 4
        return $this->attributes;
45
    }
46
47 2
    public function label(): string
48
    {
49 2
        return (string) $this->getAttribute('label');
50
    }
51
52 2
    public function setAttribute(string $key, $value): AttributeNodeInterface
53
    {
54 2
        $this->attributes[$key] = $value;
55
56 2
        return $this;
57
    }
58
59 1
    public function setAttributes(array $attributes): AttributeNodeInterface
60
    {
61 1
        $this->attributes = $attributes;
62
63 1
        return $this;
64
    }
65
}
66