LimitNodeParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 44
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 0 17 2
A supports() 0 4 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\LimitNode;
8
use Xiag\Rql\Parser\SubParserInterface;
9
10
class LimitNodeParser implements NodeParserInterface
11
{
12
    /**
13
     * @var SubParserInterface
14
     */
15
    protected $valueParser;
16
17
    /**
18
     * @param SubParserInterface $valueParser
19
     */
20 64
    public function __construct(SubParserInterface $valueParser)
21
    {
22 64
        $this->valueParser = $valueParser;
23 64
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28 5
    public function parse(TokenStream $tokenStream)
29
    {
30 5
        $limit = null;
0 ignored issues
show
Unused Code introduced by
$limit is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
31 5
        $offset = null;
32
33 5
        $tokenStream->expect(Token::T_OPERATOR, 'limit');
34 5
        $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
35
36 5
        $limit = $this->valueParser->parse($tokenStream);
37 3
        if ($tokenStream->nextIf(Token::T_COMMA)) {
38 3
            $offset = $this->valueParser->parse($tokenStream);
39 2
        }
40
41 2
        $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
42
43 1
        return new LimitNode($limit, $offset);
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49 6
    public function supports(TokenStream $tokenStream)
50
    {
51 6
        return $tokenStream->test(Token::T_OPERATOR, 'limit');
52
    }
53
}
54