Passed
Push — master ( f6567e...6c178d )
by Edward
09:59 queued 07:10
created

EvaluatedValueList::getValue()   A

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 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Value;
5
6
use Remorhaz\JSON\Data\Value\ValueInterface;
7
8
final class EvaluatedValueList implements EvaluatedValueListInterface
9
{
10
11
    private $results;
12
13
    private $indexMap;
14
15
    private $values;
16
17 14
    public function __construct(IndexMapInterface $indexMap, bool ...$results)
18
    {
19 14
        $this->indexMap = $indexMap;
20 14
        $this->results = $results;
21 14
    }
22
23 4
    public function getValue(int $index): ValueInterface
24
    {
25 4
        $values = $this->getValues();
26 4
        if (!isset($values[$index])) {
27 1
            throw new Exception\ValueNotFoundException($index, $this);
28
        }
29
30 3
        return $values[$index];
31
    }
32
33 1
    public function getIndexMap(): IndexMapInterface
34
    {
35 1
        return $this->indexMap;
36
    }
37
38 4
    public function getResults(): array
39
    {
40 4
        return $this->results;
41
    }
42
43 3
    public function getResult(int $index): bool
44
    {
45 3
        if (!isset($this->results[$index])) {
46 1
            throw new Exception\ResultNotFoundException($index, $this);
47
        }
48
49 2
        return $this->results[$index];
50
    }
51
52 6
    public function getValues(): array
53
    {
54 6
        if (!isset($this->values)) {
55 6
            $this->values = array_map([$this, 'createResultValue'], $this->results);
56
        }
57
58 6
        return $this->values;
59
    }
60
61 4
    private function createResultValue(bool $result): EvaluatedValueInterface
62
    {
63 4
        return new EvaluatedValue($result);
64
    }
65
}
66