Passed
Pull Request — master (#145)
by Christoffer
02:30
created

EnumValuesDefinitionASTBuilder::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
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 EnumValuesDefinitionASTBuilder extends AbstractASTBuilder
11
{
12
    /**
13
     * @inheritdoc
14
     */
15
    public function supportsBuilder(string $kind): bool
16
    {
17
        return $kind === ASTKindEnum::ENUM_VALUES_DEFINITION;
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function build(LexerInterface $lexer, array $params): ?array
24
    {
25
        return $this->peek($lexer, TokenKindEnum::BRACE_L)
26
            ? $this->many(
27
                $lexer,
28
                TokenKindEnum::BRACE_L,
29
                [$this, 'parseEnumValueDefinition'],
30
                TokenKindEnum::BRACE_R
31
            )
32
            : [];
33
    }
34
35
    /**
36
     * @param LexerInterface $lexer
37
     * @return array
38
     * @throws SyntaxErrorException
39
     */
40
    protected function parseEnumValueDefinition(LexerInterface $lexer): array
41
    {
42
        $start = $lexer->getToken();
43
44
        return [
45
            'kind'        => NodeKindEnum::ENUM_VALUE_DEFINITION,
46
            'description' => $this->buildAST(ASTKindEnum::DESCRIPTION, $lexer),
47
            'name'        => $this->buildAST(ASTKindEnum::NAME, $lexer),
48
            'directives'  => $this->buildAST(ASTKindEnum::DIRECTIVES, $lexer),
49
            'loc'         => $this->buildLocation($lexer, $start),
50
        ];
51
    }
52
}
53