EnumTypeExtensionNode   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 17 4
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\EnumValueDefinitionNode;
15
use Railt\SDL\Frontend\Ast\Executable\DirectiveNode;
16
use Railt\SDL\Frontend\Ast\Node;
17
18
/**
19
 * Class EnumTypeExtensionNode
20
 *
21
 * <code>
22
 *  export interface EnumTypeExtensionNode {
23
 *      readonly kind: 'EnumTypeExtension';
24
 *      readonly loc?: Location;
25
 *      readonly name: IdentifierNode;
26
 *      readonly directives?: ReadonlyArray<DirectiveNode>;
27
 *      readonly values?: ReadonlyArray<EnumValueDefinitionNode>;
28
 *  }
29
 * </code>
30
 */
31
class EnumTypeExtensionNode extends TypeExtensionNode
32
{
33
    /**
34
     * @var EnumValueDefinitionNode[]
35
     */
36
    public array $values = [];
37
38
    /**
39
     * @param array|Node[] $children
40
     * @return static
41
     */
42
    public static function create(array $children): self
43
    {
44
        $enum = new static($children[0]);
45
46
        foreach ($children as $child) {
47
            switch (true) {
48
                case $child instanceof DirectiveNode:
49
                    $enum->directives[] = $child;
50
                    break;
51
52
                case $child instanceof EnumValueDefinitionNode:
53
                    $enum->values[] = $child;
54
                    break;
55
            }
56
        }
57
58
        return $enum;
59
    }
60
}
61