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

ObjectTypeExtensionASTBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsBuilder() 0 3 1
B build() 0 23 4
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
use Digia\GraphQL\Language\TokenKindEnum;
9
10
class ObjectTypeExtensionASTBuilder extends AbstractASTBuilder
11
{
12
    /**
13
     * @inheritdoc
14
     */
15
    public function supportsBuilder(string $kind): bool
16
    {
17
        return $kind === ASTKindEnum::OBJECT_TYPE_EXTENSION;
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function build(LexerInterface $lexer, array $params): ?array
24
    {
25
        $start = $lexer->getToken();
26
27
        $this->expectKeyword($lexer, KeywordEnum::EXTEND);
28
        $this->expectKeyword($lexer, KeywordEnum::TYPE);
29
30
        $name       = $this->buildAST(ASTKindEnum::NAME, $lexer);
31
        $interfaces = $this->buildAST(ASTKindEnum::IMPLEMENTS_INTERFACES, $lexer);
32
        $directives = $this->buildAST(ASTKindEnum::DIRECTIVES, $lexer);
33
        $fields     = $this->buildAST(ASTKindEnum::FIELDS_DEFINITION, $lexer);;
34
35
        if (count($interfaces) === 0 && count($directives) === 0 && count($fields) === 0) {
36
            throw $this->unexpected($lexer);
37
        }
38
39
        return [
40
            'kind'       => NodeKindEnum::OBJECT_TYPE_EXTENSION,
41
            'name'       => $name,
42
            'interfaces' => $interfaces,
43
            'directives' => $directives,
44
            'fields'     => $fields,
45
            'loc'        => $this->buildLocation($lexer, $start),
46
        ];
47
    }
48
}
49