DirectiveDefinitionNode::create()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 25
rs 9.1111
c 0
b 0
f 0
cc 6
nc 6
nop 1
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\Frontend\Ast\Definition;
13
14
use Railt\SDL\Frontend\Ast\Description;
15
use Railt\SDL\Frontend\Ast\Identifier;
16
use Railt\SDL\Frontend\Ast\Node;
17
use Railt\TypeSystem\Value\StringValue;
18
19
/**
20
 * Class DirectiveDefinitionNode
21
 *
22
 * <code>
23
 *  export interface DirectiveDefinitionNode {
24
 *      readonly kind: 'DirectiveDefinition';
25
 *      readonly loc?: Location;
26
 *      readonly description?: StringValueNode;
27
 *      readonly name: IdentifierNode;
28
 *      readonly arguments?: ReadonlyArray<InputValueDefinitionNode>;
29
 *      readonly repeatable: boolean;
30
 *      readonly locations: ReadonlyArray<IdentifierNode>;
31
 *  }
32
 * </code>
33
 */
34
class DirectiveDefinitionNode extends TypeSystemDefinitionNode
35
{
36
    /**
37
     * @var Identifier
38
     */
39
    public Identifier $name;
40
41
    /**
42
     * @var DirectiveDefinitionIsRepeatableNode|null
43
     */
44
    public ?DirectiveDefinitionIsRepeatableNode $repeatable = null;
45
46
    /**
47
     * @var DirectiveDefinitionLocationNode[]
48
     */
49
    public array $locations = [];
50
51
    /**
52
     * @var StringValue|null
53
     */
54
    public ?StringValue $description = null;
55
56
    /**
57
     * @var ArgumentDefinitionNode[]
58
     */
59
    public array $arguments = [];
60
61
    /**
62
     * TypeDefinitionNode constructor.
63
     *
64
     * @param Identifier $name
65
     */
66
    public function __construct(Identifier $name)
67
    {
68
        $this->name = $name;
69
    }
70
71
    /**
72
     * @param array|Node[] $children
73
     * @return static
74
     */
75
    public static function create(array $children): self
76
    {
77
        $directive = new static($children[1]);
78
79
        foreach ($children as $child) {
80
            switch (true) {
81
                case $child instanceof Description:
82
                    $directive->description = $child->value;
83
                    break;
84
85
                case $child instanceof DirectiveDefinitionLocationNode:
0 ignored issues
show
Bug introduced by
The type Railt\SDL\Frontend\Ast\D...eDefinitionLocationNode was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
86
                    $directive->locations[] = $child;
87
                    break;
88
89
                case $child instanceof DirectiveDefinitionIsRepeatableNode:
90
                    $directive->repeatable = $child;
91
                    break;
92
93
                case $child instanceof ArgumentDefinitionNode:
94
                    $directive->arguments[] = $child;
95
                    break;
96
            }
97
        }
98
99
        return $directive;
100
    }
101
}
102