Test Setup Failed
Push — master ( 050b68...43996d )
by Kirill
03:02
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
<?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\DirectiveInterface;
15
use Railt\SDL\Frontend\Ast\Definition\DirectiveDefinitionLocationNode as LocationNode;
16
use Railt\SDL\Frontend\Ast\Definition\DirectiveDefinitionNode;
17
use Railt\TypeSystem\Directive;
18
19
/**
20
 * @property-read DirectiveDefinitionNode $ast
21
 */
22
final class DirectiveDefinitionContext extends DefinitionContext
23
{
24
    /**
25
     * @param array $args
26
     * @return DirectiveInterface
27
     * @throws \Throwable
28
     */
29
    public function build(array $args): DirectiveInterface
30
    {
31
        $locations = \array_map(fn(LocationNode $loc): string => $loc->name->value, $this->ast->locations);
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected ':', expecting T_DOUBLE_ARROW on line 31 at column 53
Loading history...
32
33
        return new Directive($this->getName(), [
34
            'description' => $this->description($this->ast),
35
            'repeatable'  => $this->ast->repeatable !== null,
36
            'locations'   => $locations,
37
        ]);
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getName(): string
44
    {
45
        return $this->ast->name->value;
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getGenericArguments(): array
52
    {
53
        return [];
54
    }
55
}
56