FieldDefinitionNode::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\DefinitionNode;
15
use Railt\SDL\Frontend\Ast\Description;
16
use Railt\SDL\Frontend\Ast\Executable\DirectiveNode;
17
use Railt\SDL\Frontend\Ast\Generic\ArgumentDefinitionCollection;
0 ignored issues
show
Bug introduced by
The type Railt\SDL\Frontend\Ast\G...entDefinitionCollection 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...
18
use Railt\SDL\Frontend\Ast\Generic\DirectiveCollection;
0 ignored issues
show
Bug introduced by
The type Railt\SDL\Frontend\Ast\Generic\DirectiveCollection 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...
19
use Railt\SDL\Frontend\Ast\Identifier;
20
use Railt\SDL\Frontend\Ast\Node;
21
use Railt\SDL\Frontend\Ast\Type\TypeNode;
22
use Railt\TypeSystem\Value\StringValue;
23
24
/**
25
 * <code>
26
 *  export interface FieldDefinitionNode {
27
 *      readonly kind: 'FieldDefinition';
28
 *      readonly loc?: Location;
29
 *      readonly description?: StringValueNode;
30
 *      readonly name: IdentifierNode;
31
 *      readonly arguments?: ReadonlyArray<InputValueDefinitionNode>;
32
 *      readonly type: TypeNode;
33
 *      readonly directives?: ReadonlyArray<DirectiveNode>;
34
 *  }
35
 * </code>
36
 */
37
class FieldDefinitionNode extends DefinitionNode
38
{
39
    /**
40
     * @var Identifier
41
     */
42
    public Identifier $name;
43
44
    /**
45
     * @var TypeNode
46
     */
47
    public TypeNode $type;
48
49
    /**
50
     * @var StringValue|null
51
     */
52
    public ?StringValue $description = null;
53
54
    /**
55
     * @var DirectiveNode[]
56
     */
57
    public array $directives = [];
58
59
    /**
60
     * @var ArgumentDefinitionNode[]
61
     */
62
    public array $arguments = [];
63
64
    /**
65
     * TypeDefinitionNode constructor.
66
     *
67
     * @param Identifier $name
68
     */
69
    public function __construct(Identifier $name)
70
    {
71
        $this->name = $name;
72
    }
73
74
    /**
75
     * @param array|Node[] $children
76
     * @return static
77
     */
78
    public static function create(array $children): self
79
    {
80
        $field = new static($children[1]);
81
82
        foreach ($children as $child) {
83
            switch (true) {
84
                case $child instanceof Description:
85
                    $field->description = $child->value;
86
                    break;
87
88
                case $child instanceof TypeNode:
89
                    $field->type = $child;
90
                    break;
91
92
                case $child instanceof DirectiveNode:
93
                    $field->directives[] = $child;
94
                    break;
95
96
                case $child instanceof ArgumentDefinitionNode:
97
                    $field->arguments[] = $child;
98
                    break;
99
            }
100
        }
101
102
        return $field;
103
    }
104
}
105