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

ScalarTypeExtensionASTBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsBuilder() 0 3 1
A build() 0 19 2
1
<?php
2
3
namespace Digia\GraphQL\Language\ASTBuilder;
4
5
use Digia\GraphQL\Language\KeywordEnum;
6
use Digia\GraphQL\Language\LexerInterface;
7
use Digia\GraphQL\Language\Node\NodeKindEnum;
8
9
class ScalarTypeExtensionASTBuilder extends AbstractASTBuilder
10
{
11
    /**
12
     * @inheritdoc
13
     */
14
    public function supportsBuilder(string $kind): bool
15
    {
16
        return $kind === ASTKindEnum::SCALAR_TYPE_EXTENSION;
17
    }
18
19
    /**
20
     * @inheritdoc
21
     */
22
    public function build(LexerInterface $lexer, array $params): ?array
23
    {
24
        $start = $lexer->getToken();
25
26
        $this->expectKeyword($lexer, KeywordEnum::EXTEND);
27
        $this->expectKeyword($lexer, KeywordEnum::SCALAR);
28
29
        $name       = $this->buildAST(ASTKindEnum::NAME, $lexer);
30
        $directives = $this->buildAST(ASTKindEnum::DIRECTIVES, $lexer);
31
32
        if (count($directives) === 0) {
33
            throw $this->unexpected($lexer);
34
        }
35
36
        return [
37
            'kind'       => NodeKindEnum::SCALAR_TYPE_EXTENSION,
38
            'name'       => $name,
39
            'directives' => $directives,
40
            'loc'        => $this->buildLocation($lexer, $start),
41
        ];
42
    }
43
}
44