Parser   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 33.9 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 20
loc 59
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
getNameFor() 0 1 ?
A getParseError() 0 9 2
A expect() 0 11 2
A accept() 10 10 2
A is() 10 10 2

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
3
namespace HansOtt\GraphQL\Shared;
4
5
abstract class Parser
6
{
7
    /**
8
     * @var ScannerTokens
9
     */
10
    protected $scanner;
11
    protected $lexer;
12
13 117
    final public function __construct(Lexer $lexer)
14
    {
15 117
        $this->lexer = $lexer;
16 117
    }
17
18
    abstract protected function getNameFor($tokenType);
19
20 24
    final protected function getParseError($message)
21
    {
22 24
        $token = $this->scanner->getLastToken();
23 24
        if ($this->scanner->eof() === false) {
24 15
            $token = $this->scanner->peek();
25 15
        }
26
27 24
        return new ParseError($message . " (line {$token->location->line}, column {$token->location->column})");
28
    }
29
30 81
    final protected function expect($tokenType)
31
    {
32 81
        $token = $this->scanner->next();
33
34 81
        if ($token->type !== $tokenType) {
35 9
            $expectedToken = $this->getNameFor($tokenType);
36 9
            throw $this->getParseError("Expected \"{$expectedToken}\" but instead found \"{$token->getName()}\" with value \"{$token->value}\"");
37
        }
38
39 81
        return $token;
40
    }
41
42 75 View Code Duplication
    final protected function accept($tokenType)
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...
43
    {
44 75
        $token = $this->scanner->peek();
45
46 75
        if ($token->type !== $tokenType) {
47 75
            return false;
48
        }
49
50 54
        return $this->scanner->next();
51
    }
52
53 78 View Code Duplication
    final protected function is($tokenType)
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...
54
    {
55 78
        if ($this->scanner->eof()) {
56 6
            return false;
57
        }
58
59 78
        $token = $this->scanner->peek();
60
61 78
        return $token->type === $tokenType;
62
    }
63
}
64