PathParser::parseInner()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cloudstek\SCIM\FilterParser;
6
7
use Cloudstek\SCIM\FilterParser\Exception\UnexpectedValueException;
8
use Nette\Tokenizer;
9
10
/**
11
 * SCIM Path Parser.
12
 */
13
class PathParser extends AbstractParser implements PathParserInterface
14
{
15
    /**
16
     * SCIM Path Parser.
17
     */
18
    public function __construct()
19
    {
20
        parent::__construct(ParserMode::PATH);
1 ignored issue
show
Bug introduced by
The type Cloudstek\SCIM\FilterParser\ParserMode was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
    }
22
23
    /**
24
     * Parse path string.
25
     *
26
     * @param string $input Attribute path..
27
     *
28
     * @throws Tokenizer\Exception
29
     *
30
     * @return AST\Path
31
     */
32
    public function parse(string $input): AST\Path
33
    {
34
        $stream = $this->tokenizer->tokenize($input);
35
36
        // Attribute path
37
        $attributePath = $this->parseAttributePath($stream);
38
39
        if ($stream->nextToken() !== null) {
40
            throw new UnexpectedValueException($stream);
41
        }
42
43
        return $attributePath;
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49
    protected function parseInner(Tokenizer\Stream $stream, bool $inValuePath = false): ?AST\Node
50
    {
51
        // @codeCoverageIgnoreStart
52
        if ($inValuePath === false) {
53
            throw new \LogicException('This method should only be called when parsing a value path.');
54
        }
55
56
        // @codeCoverageIgnoreEnd
57
58
        return parent::parseInner($stream, $inValuePath);
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    protected function parseValuePath(Tokenizer\Stream $stream, AST\AttributePath $attributePath): AST\ValuePath
65
    {
66
        $valuePath = parent::parseValuePath($stream, $attributePath);
67
68
        // Sub attribute
69
        if ($stream->isNext()) {
70
            $subAttr = $stream->consumeToken(self::T_SUBATTR)->value;
71
72
            // Strip off the '.' at the start
73
            $subAttr = ltrim($subAttr, '.');
74
75
            // Append to attribute path.
76
            $names = $attributePath->getNames();
77
            $names[] = $subAttr;
78
79
            $valuePath->setAttributePath(
80
                new AST\AttributePath(
81
                    $attributePath->getSchema(),
82
                    $names
83
                )
84
            );
85
        }
86
87
        return $valuePath;
88
    }
89
}
90