AttributeNode   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 50
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setAttribute() 0 5 1
A __construct() 0 9 1
A getAttribute() 0 3 1
A getAttributes() 0 3 1
A setAttributes() 0 5 1
A label() 0 3 1
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