EvaluatedValueList   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 56
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getValues() 0 7 2
A createResultValue() 0 3 1
A getValue() 0 8 2
A getResult() 0 7 2
A getIndexMap() 0 3 1
A getResults() 0 3 1
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
final class EvaluatedValueList implements EvaluatedValueListInterface
10
{
11
12
    private $results;
13
14
    private $indexMap;
15
16
    private $values;
17
18 14
    public function __construct(IndexMapInterface $indexMap, bool ...$results)
19
    {
20 14
        $this->indexMap = $indexMap;
21 14
        $this->results = $results;
22 14
    }
23
24 4
    public function getValue(int $index): ValueInterface
25
    {
26 4
        $values = $this->getValues();
27 4
        if (!isset($values[$index])) {
28 1
            throw new Exception\ValueNotFoundException($index, $this);
29
        }
30
31 3
        return $values[$index];
32
    }
33
34 1
    public function getIndexMap(): IndexMapInterface
35
    {
36 1
        return $this->indexMap;
37
    }
38
39 4
    public function getResults(): array
40
    {
41 4
        return $this->results;
42
    }
43
44 3
    public function getResult(int $index): bool
45
    {
46 3
        if (!isset($this->results[$index])) {
47 1
            throw new Exception\ResultNotFoundException($index, $this);
48
        }
49
50 2
        return $this->results[$index];
51
    }
52
53 6
    public function getValues(): array
54
    {
55 6
        if (!isset($this->values)) {
56 6
            $this->values = array_map([$this, 'createResultValue'], $this->results);
57
        }
58
59 6
        return $this->values;
60
    }
61
62 4
    private function createResultValue(bool $result): EvaluatedValueInterface
63
    {
64 4
        return new EvaluatedValue($result);
65
    }
66
}
67