SelectNodeParser::parse()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 18
loc 18
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 2
nop 1
crap 3
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