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

InputValueDefinitionASTBuilder::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 14

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 14
nc 2
nop 2
1
<?php
2
3
namespace Digia\GraphQL\Language\ASTBuilder;
4
5
use Digia\GraphQL\Language\LexerInterface;
6
use Digia\GraphQL\Language\Node\NodeKindEnum;
7
use Digia\GraphQL\Language\TokenKindEnum;
8
9
class InputValueDefinitionASTBuilder extends AbstractASTBuilder
10
{
11
    /**
12
     * @inheritdoc
13
     */
14
    public function supportsBuilder(string $kind): bool
15
    {
16
        return $kind === ASTKindEnum::INPUT_VALUE_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
        $name        = $this->buildAST(ASTKindEnum::NAME, $lexer);
28
29
        $this->expect($lexer, TokenKindEnum::COLON);
30
31
        return [
32
            'kind'         => NodeKindEnum::INPUT_VALUE_DEFINITION,
33
            'description'  => $description,
34
            'name'         => $name,
35
            'type'         => $this->buildAST(ASTKindEnum::TYPE_REFERENCE, $lexer),
36
            'defaultValue' => $this->skip($lexer, TokenKindEnum::EQUALS)
37
                ? $this->buildAST(ASTKindEnum::VALUE, $lexer, ['isConst' => true])
38
                : null,
39
            'directives'   => $this->buildAST(ASTKindEnum::DIRECTIVES, $lexer, ['isConst' => true]),
40
            'loc'          => $this->buildLocation($lexer, $start),
41
        ];
42
    }
43
}
44