Completed
Branch master (82de9e)
by Edward
02:36
created

QueryValidator::getDefinitePathQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Query;
5
6
use Remorhaz\JSON\Path\Processor\Exception;
7
8
final class QueryValidator implements QueryValidatorInterface
9
{
10
11
    public function getDefiniteQuery(QueryInterface $query): QueryInterface
12
    {
13
        if (!$query->getCapabilities()->isDefinite()) {
14
            throw new Exception\IndefiniteQueryException($query);
15
        }
16
17
        return $query;
18
    }
19
20
    public function getPathQuery(QueryInterface $query): QueryInterface
21
    {
22
        if (!$query->getCapabilities()->isPath()) {
23
            throw new Exception\PathNotSelectableException($query);
24
        }
25
26
        return $query;
27
    }
28
29
    public function getDefinitePathQuery(QueryInterface $query): QueryInterface
30
    {
31
        return $this->getPathQuery($this->getDefiniteQuery($query));
32
    }
33
}
34