SelectNodeParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 40 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 18
loc 45
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 18 18 3
A supports() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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