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

StrictPropertyMatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 3 1
A __construct() 0 3 1
A getSortIndex() 0 9 2
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