InputObjectTypeDefinitionNode::create()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 21
rs 9.5222
c 0
b 0
f 0
cc 5
nc 5
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\Type;
13
14
use Railt\SDL\Frontend\Ast\Definition\InputFieldDefinitionNode;
15
use Railt\SDL\Frontend\Ast\Description;
16
use Railt\SDL\Frontend\Ast\Executable\DirectiveNode;
17
use Railt\SDL\Frontend\Ast\Node;
18
19
/**
20
 * Class InputObjectTypeDefinitionNode
21
 *
22
 * <code>
23
 *  export interface InputObjectTypeDefinitionNode {
24
 *      readonly kind: 'InputObjectTypeDefinition';
25
 *      readonly loc?: Location;
26
 *      readonly description?: StringValueNode;
27
 *      readonly name: IdentifierNode;
28
 *      readonly directives?: ReadonlyArray<DirectiveNode>;
29
 *      readonly fields?: ReadonlyArray<InputValueDefinitionNode>;
30
 *  }
31
 * </code>
32
 */
33
class InputObjectTypeDefinitionNode extends TypeDefinitionNode
34
{
35
    /**
36
     * @var InputFieldDefinitionNode[]
37
     */
38
    public array $fields = [];
39
40
    /**
41
     * @param array|Node[] $children
42
     * @return static
43
     */
44
    public static function create(array $children): self
45
    {
46
        $input = new static($children[1]);
47
48
        foreach ($children as $child) {
49
            switch (true) {
50
                case $child instanceof Description:
51
                    $input->description = $child->value;
52
                    break;
53
54
                case $child instanceof DirectiveNode:
55
                    $input->directives[] = $child;
56
                    break;
57
58
                case $child instanceof InputFieldDefinitionNode:
59
                    $input->fields[] = $child;
60
                    break;
61
            }
62
        }
63
64
        return $input;
65
    }
66
}
67