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

ScalarTypeExtensionASTBuilder::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 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