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

InterfaceTypeExtensionASTBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 21 3
A supportsBuilder() 0 3 1
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