AttributeCollection::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\Lexer\Runtime\Token;
6
7
/**
8
 * @psalm-immutable
9
 */
10
final class AttributeCollection implements AttributeCollectionInterface
11
{
12
13
    /**
14
     * @var AttributeInterface[]
15
     * @psalm-var array<string,AttributeInterface>
16
     */
17
    private $attributeMap = [];
18
19
    /**
20
     * @param AttributeInterface[] $attributeMap
21
     * @psalm-param array<string,AttributeInterface> $attributeMap
22
     */
23 4
    public function __construct(array $attributeMap = [])
24
    {
25 4
        $this->attributeMap = $attributeMap;
26 4
    }
27
28
    /**
29
     * @param string $name
30
     * @return AttributeInterface
31
     * @psalm-pure
32
     */
33 2
    public function get(string $name): AttributeInterface
34
    {
35 2
        if (isset($this->attributeMap[$name])) {
36 1
            return $this->attributeMap[$name];
37
        }
38
39 1
        throw new Exception\AttributeNotFoundException($name);
40
    }
41
42
    /**
43
     * @param string $name
44
     * @return bool
45
     * @psalm-pure
46
     */
47 2
    public function has(string $name): bool
48
    {
49 2
        return isset($this->attributeMap[$name]);
50
    }
51
}
52