Passed
Push — master ( fc0629...9e5c60 )
by Edward
05:11
created

StrictPropertyMatcher::getSortIndex()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Runtime\Matcher;
5
6
use function in_array;
7
use Remorhaz\JSON\Data\Value\NodeValueInterface;
8
9
final class StrictPropertyMatcher implements SortedChildMatcherInterface
10
{
11
12
    private $properties;
13
14 3
    public function __construct(string ...$properties)
15
    {
16 3
        $this->properties = $properties;
17 3
    }
18
19 3
    public function match($address, NodeValueInterface $value, NodeValueInterface $container): bool
20
    {
21 3
        return in_array($address, $this->properties, true);
22
    }
23
24
    public function getSortIndex($address, NodeValueInterface $value, NodeValueInterface $container): int
25
    {
26
        $index = array_search($address, $this->properties);
27
28
        if (is_int($index)) {
29
            return $index;
30
        }
31
32
        throw new Exception\AddressNotSortableException($address);
33
    }
34
}
35