Passed
Push — master ( c47e08...96e565 )
by Quang
02:51
created

DirectivesASTBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsBuilder() 0 3 1
A build() 0 11 2
A parseDirective() 0 11 1
1
<?php
2
3
namespace Digia\GraphQL\Language\ASTBuilder;
4
5
use Digia\GraphQL\Error\SyntaxErrorException;
6
use Digia\GraphQL\Language\LexerInterface;
7
use Digia\GraphQL\Language\Node\NodeKindEnum;
8
use Digia\GraphQL\Language\TokenKindEnum;
9
10
class DirectivesASTBuilder extends AbstractASTBuilder
11
{
12
    /**
13
     * @inheritdoc
14
     */
15
    public function supportsBuilder(string $kind): bool
16
    {
17
        return $kind === ASTKindEnum::DIRECTIVES;
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function build(LexerInterface $lexer, array $params): ?array
24
    {
25
        $isConst = $params['isConst'] ?? false;
26
27
        $directives = [];
28
29
        while ($this->peek($lexer, TokenKindEnum::AT)) {
30
            $directives[] = $this->parseDirective($lexer, $isConst);
31
        }
32
33
        return $directives;
34
    }
35
36
    /**
37
     * @param LexerInterface $lexer
38
     * @param bool           $isConst
39
     * @return array
40
     * @throws SyntaxErrorException
41
     */
42
    protected function parseDirective(LexerInterface $lexer, bool $isConst): array
0 ignored issues
show
Unused Code introduced by
The parameter $isConst is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

42
    protected function parseDirective(LexerInterface $lexer, /** @scrutinizer ignore-unused */ bool $isConst): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44
        $start = $lexer->getToken();
45
46
        $this->expect($lexer, TokenKindEnum::AT);
47
48
        return [
49
            'kind'      => NodeKindEnum::DIRECTIVE,
50
            'name'      => $this->buildAST(ASTKindEnum::NAME, $lexer),
51
            'arguments' => $this->buildAST(ASTKindEnum::ARGUMENTS, $lexer),
52
            'loc'       => $this->buildLocation($lexer, $start),
53
        ];
54
    }
55
}
56