Test Setup Failed
Push — master ( 1595cb...050b68 )
by Kirill
21:00
created

DirectiveDefinitionContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
dl 0
loc 23
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 16 3
1
<?php
2
3
/**
4
 * This file is part of Railt package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Railt\SDL\Backend\Context;
13
14
use GraphQL\Contracts\TypeSystem\DefinitionInterface;
15
use Railt\SDL\Frontend\Ast\Definition\DirectiveDefinitionNode;
16
use Railt\TypeSystem\Directive;
17
18
/**
19
 * @property-read DirectiveDefinitionNode $ast
20
 */
21
class DirectiveDefinitionContext extends ObjectLikeTypeDefinitionContext
22
{
23
    /**
24
     * @param array $args
25
     * @return DefinitionInterface
26
     * @throws \Throwable
27
     */
28
    public function resolve(array $args = []): DefinitionInterface
29
    {
30
        $directive = new Directive($this->ast->name->value, [
31
            'description' => $this->descriptionOf($this->ast),
32
            'repeatable'  => $this->ast->repeatable !== null,
33
        ]);
34
35
        foreach ($this->ast->locations as $location) {
36
            $directive->addLocation($location->name->value);
37
        }
38
39
        foreach ($this->ast->arguments as $arg) {
40
            $directive->addArgument($this->buildArgumentDefinition($arg, $args));
41
        }
42
43
        return $directive;
44
    }
45
}
46