SelectNodeParser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Xiag\Rql\Parser\NodeParser;
3
4
use Xiag\Rql\Parser\Token;
5
use Xiag\Rql\Parser\TokenStream;
6
use Xiag\Rql\Parser\NodeParserInterface;
7
use Xiag\Rql\Parser\Node\SelectNode;
8
use Xiag\Rql\Parser\SubParserInterface;
9
10
class SelectNodeParser implements NodeParserInterface
11
{
12
    /**
13
     * @var SubParserInterface
14
     */
15
    protected $fieldNameParser;
16
17
    /**
18
     * @param SubParserInterface $fieldNameParser
19
     */
20 64
    public function __construct(SubParserInterface $fieldNameParser)
21
    {
22 64
        $this->fieldNameParser = $fieldNameParser;
23 64
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28 1 View Code Duplication
    public function parse(TokenStream $tokenStream)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30 1
        $fields = [];
31
32 1
        $tokenStream->expect(Token::T_OPERATOR, 'select');
33 1
        $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
34
35
        do {
36 1
            $fields[] = $this->fieldNameParser->parse($tokenStream);
37 1
            if (!$tokenStream->nextIf(Token::T_COMMA)) {
38 1
                break;
39
            }
40 1
        } while (true);
41
42 1
        $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
43
44 1
        return new SelectNode($fields);
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50 6
    public function supports(TokenStream $tokenStream)
51
    {
52 6
        return $tokenStream->test(Token::T_OPERATOR, 'select');
53
    }
54
}
55