Completed
Pull Request — master (#148)
by Christoffer
04:19
created

InterfaceTypeExtensionASTBuilder::build()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 14
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 InterfaceTypeExtensionASTBuilder extends AbstractASTBuilder
10
{
11
    /**
12
     * @inheritdoc
13
     */
14
    public function supportsBuilder(string $kind): bool
15
    {
16
        return $kind === ASTKindEnum::INTERFACE_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::INTERFACE);
28
29
        $name       = $this->buildAST(ASTKindEnum::NAME, $lexer);
30
        $directives = $this->buildAST(ASTKindEnum::DIRECTIVES, $lexer);
31
        $fields     = $this->buildAST(ASTKindEnum::FIELDS_DEFINITION, $lexer);
32
33
        if (count($directives) === 0 && count($fields) === 0) {
34
            throw $this->unexpected($lexer);
35
        }
36
37
        return [
38
            'kind'       => NodeKindEnum::INTERFACE_TYPE_EXTENSION,
39
            'name'       => $name,
40
            'directives' => $directives,
41
            'fields'     => $fields,
42
            'loc'        => $this->buildLocation($lexer, $start),
43
        ];
44
    }
45
}
46