Passed
Push — develop ( cb60d7...ef7d65 )
by Maarten de
07:14
created

FilterParser::parseFilter()   B

Complexity

Conditions 8
Paths 27

Size

Total Lines 40
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 19
c 1
b 0
f 0
nc 27
nop 2
dl 0
loc 40
rs 8.4444
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cloudstek\SCIM\FilterParser;
6
7
use Cloudstek\SCIM\FilterParser\Exception\InvalidValuePathException;
8
use Cloudstek\SCIM\FilterParser\Exception\TokenizerException;
9
10
/**
11
 * SCIM Filter Parser.
12
 */
13
class FilterParser extends AbstractParser implements FilterParserInterface
14
{
15
    /**
16
     * SCIM Filter Parser.
17
     */
18
    public function __construct()
19
    {
20
        parent::__construct(ParserMode::FILTER());
21
    }
22
23
    /**
24
     * Parse filter string.
25
     *
26
     * @param string $input Filter.
27
     *
28
     * @throws TokenizerException|\Nette\Tokenizer\Exception
29
     *
30
     * @return AST\Node|null
31
     */
32
    public function parse(string $input): ?AST\Node
33
    {
34
        $stream = $this->tokenizer->tokenize($input);
35
36
        return $this->parseInner($stream);
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    protected function parseValuePath(Tokenizer\Stream $stream, AST\AttributePath $attributePath): AST\ValuePath
43
    {
44
        $valuePath = parent::parseValuePath($stream, $attributePath);
45
46
        if ($stream->isNext(self::T_SUBATTR)) {
47
            throw new InvalidValuePathException($stream, 'Invalid value path, unexpected sub attribute.');
48
        }
49
50
        return $valuePath;
51
    }
52
}
53