Passed
Push — master ( 81686d...1595cb )
by Kirill
04:41
created

EnumValueDefinitionNode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
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\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\Identifier;
18
use Railt\SDL\Frontend\Ast\Node;
19
use Railt\TypeSystem\Value\StringValue;
20
21
/**
22
 * Class EnumValueDefinitionNode
23
 *
24
 * <code>
25
 *  export interface EnumValueDefinitionNode {
26
 *      readonly kind: 'EnumValueDefinition';
27
 *      readonly loc?: Location;
28
 *      readonly description?: StringValueNode;
29
 *      readonly name: IdentifierNode;
30
 *      readonly directives?: ReadonlyArray<DirectiveNode>;
31
 *  }
32
 * </code>
33
 */
34
class EnumValueDefinitionNode extends DefinitionNode
35
{
36
    /**
37
     * @var Identifier
38
     */
39
    public Identifier $name;
40
41
    /**
42
     * @var StringValue|null
43
     */
44
    public ?StringValue $description = null;
45
46
    /**
47
     * @var DirectiveNode[]
48
     */
49
    public array $directives = [];
50
51
    /**
52
     * EnumValueDefinitionNode constructor.
53
     *
54
     * @param Identifier $name
55
     */
56
    public function __construct(Identifier $name)
57
    {
58
        $this->name = $name;
59
    }
60
61
    /**
62
     * @param array|Node[] $children
63
     * @return static
64
     */
65
    public static function create(array $children): self
66
    {
67
        $value = new static($children[1]);
68
69
        foreach ($children as $child) {
70
            switch (true) {
71
                case $child instanceof Description:
72
                    $value->description = $child->value;
73
                    break;
74
75
                case $child instanceof DirectiveNode:
76
                    $value->directives[] = $child;
77
                    break;
78
            }
79
        }
80
81
        return $value;
82
    }
83
}
84