LiteralValueList::getValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Path\Value;
6
7
use Remorhaz\JSON\Data\Value\ValueInterface;
8
9
use function array_fill_keys;
10
11
final class LiteralValueList implements LiteralValueListInterface
12
{
13
14
    private $indexMap;
15
16
    private $value;
17
18 5
    public function __construct(IndexMapInterface $indexMap, LiteralValueInterface $value)
19
    {
20 5
        $this->indexMap = $indexMap;
21 5
        $this->value = $value;
22 5
    }
23
24 1
    public function getLiteral(): LiteralValueInterface
25
    {
26 1
        return $this->value;
27
    }
28
29 2
    public function getValue(int $index): ValueInterface
30
    {
31 2
        $innerIndexes = $this->indexMap->getInnerIndexes();
32 2
        if (!isset($innerIndexes[$index])) {
33 1
            throw new Exception\ValueNotFoundException($index, $this);
34
        }
35
36 1
        return $this->value;
37
    }
38
39 1
    public function getValues(): array
40
    {
41 1
        return array_fill_keys($this->indexMap->getInnerIndexes(), $this->value);
42
    }
43
44 1
    public function getIndexMap(): IndexMapInterface
45
    {
46 1
        return $this->indexMap;
47
    }
48
}
49