ArgumentDefinitionNode::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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\SDL\Frontend\Ast\Type\TypeNode;
20
use Railt\TypeSystem\Value\StringValue;
21
use Railt\TypeSystem\Value\ValueInterface;
22
23
/**
24
 * Class ArgumentDefinitionNode
25
 */
26
class ArgumentDefinitionNode extends DefinitionNode
27
{
28
    /**
29
     * @var Identifier
30
     */
31
    public Identifier $name;
32
33
    /**
34
     * @var TypeNode
35
     */
36
    public TypeNode $type;
37
38
    /**
39
     * @var StringValue|null
40
     */
41
    public ?StringValue $description = null;
42
43
    /**
44
     * @var DirectiveNode[]
45
     */
46
    public array $directives = [];
47
48
    /**
49
     * @var ValueInterface|null
50
     */
51
    public ?ValueInterface $defaultValue = null;
52
53
    /**
54
     * TypeDefinitionNode constructor.
55
     *
56
     * @param Identifier $name
57
     * @param TypeNode $type
58
     */
59
    public function __construct(Identifier $name, TypeNode $type)
60
    {
61
        $this->name = $name;
62
        $this->type = $type;
63
    }
64
65
    /**
66
     * @param array|Node[] $children
67
     * @return static
68
     */
69
    public static function create(array $children): self
70
    {
71
        $value = new static($children[1], $children[2]);
72
73
        foreach ($children as $child) {
74
            switch (true) {
75
                case $child instanceof Description:
76
                    $value->description = $child->value;
77
                    break;
78
79
                case $child instanceof DirectiveNode:
80
                    $value->directives[] = $child;
81
                    break;
82
83
                case $child instanceof ValueInterface:
84
                    $value->defaultValue = $child;
85
                    break;
86
            }
87
        }
88
89
        return $value;
90
    }
91
}
92