Passed
Pull Request — master (#145)
by Christoffer
03:59 queued 01:32
created

ScalarTypeDefinitionASTBuilder::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
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 ScalarTypeDefinitionASTBuilder extends AbstractASTBuilder
10
{
11
    /**
12
     * @inheritdoc
13
     */
14
    public function supportsBuilder(string $kind): bool
15
    {
16
        return $kind === ASTKindEnum::SCALAR_TYPE_DEFINITION;
17
    }
18
19
    /**
20
     * @inheritdoc
21
     */
22
    public function build(LexerInterface $lexer, array $params): ?array
23
    {
24
        $start = $lexer->getToken();
25
26
        $description = $this->buildAST(ASTKindEnum::DESCRIPTION, $lexer);
27
28
        $this->expectKeyword($lexer, KeywordEnum::SCALAR);
29
30
        return [
31
            'kind'        => NodeKindEnum::SCALAR_TYPE_DEFINITION,
32
            'description' => $description,
33
            'name'        => $this->buildAST(ASTKindEnum::NAME, $lexer),
34
            'directives'  => $this->buildAST(ASTKindEnum::DIRECTIVES, $lexer),
35
            'loc'         => $this->buildLocation($lexer, $start),
36
        ];
37
    }
38
}
39