InputObjectTypeExtensionNode::create()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 17
rs 9.9332
c 0
b 0
f 0
cc 4
nc 4
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\Extension\Type;
13
14
use Railt\SDL\Frontend\Ast\Definition\InputFieldDefinitionNode;
15
use Railt\SDL\Frontend\Ast\Definition\Type\InputObjectTypeDefinitionNode;
16
use Railt\SDL\Frontend\Ast\Description;
17
use Railt\SDL\Frontend\Ast\Executable\DirectiveNode;
18
use Railt\SDL\Frontend\Ast\Node;
19
20
/**
21
 * Class InputObjectTypeExtensionNode
22
 *
23
 * <code>
24
 *  export interface InputObjectTypeExtensionNode {
25
 *      readonly kind: 'InputObjectTypeExtension';
26
 *      readonly loc?: Location;
27
 *      readonly name: IdentifierNode;
28
 *      readonly directives?: ReadonlyArray<DirectiveNode>;
29
 *      readonly fields?: ReadonlyArray<InputValueDefinitionNode>;
30
 *  }
31
 * </code>
32
 */
33
class InputObjectTypeExtensionNode extends TypeExtensionNode
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[0]);
47
48
        foreach ($children as $child) {
49
            switch (true) {
50
                case $child instanceof DirectiveNode:
51
                    $input->directives[] = $child;
52
                    break;
53
54
                case $child instanceof InputFieldDefinitionNode:
55
                    $input->fields[] = $child;
56
                    break;
57
            }
58
        }
59
60
        return $input;
61
    }
62
}
63