StrictElementMatcher   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 24
ccs 5
cts 10
cp 0.5
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getSortIndex() 0 9 2
A match() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Path\Runtime\Matcher;
6
7
use Remorhaz\JSON\Data\Value\NodeValueInterface;
8
9
use function array_search;
10
use function in_array;
11
use function is_int;
12
13
final class StrictElementMatcher implements SortedChildMatcherInterface
14
{
15
16
    private $indexes;
17
18 3
    public function __construct(int ...$indexes)
19
    {
20 3
        $this->indexes = $indexes;
21 3
    }
22
23 3
    public function match($address, NodeValueInterface $value, NodeValueInterface $container): bool
24
    {
25 3
        return in_array($address, $this->indexes, true);
26
    }
27
28
    public function getSortIndex($address, NodeValueInterface $value, NodeValueInterface $container): int
29
    {
30
        $index = array_search($address, $this->indexes);
31
32
        if (is_int($index)) {
33
            return $index;
34
        }
35
36
        throw new Exception\AddressNotSortableException($address);
37
    }
38
}
39