ScalarTypeExtensionNode::create()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 3
nc 3
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\Type\ScalarTypeDefinitionNode;
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 ScalarTypeExtensionNode
21
 *
22
 * <code>
23
 *  export interface ScalarTypeExtensionNode {
24
 *      readonly kind: 'ScalarTypeExtension';
25
 *      readonly loc?: Location;
26
 *      readonly name: IdentifierNode;
27
 *      readonly directives?: ReadonlyArray<DirectiveNode>;
28
 *  }
29
 * </code>
30
 */
31
class ScalarTypeExtensionNode extends TypeExtensionNode
32
{
33
    /**
34
     * @param array|Node[] $children
35
     * @return static
36
     */
37
    public static function create(array $children): self
38
    {
39
        $scalar = new static($children[0]);
40
41
        foreach ($children as $child) {
42
            switch (true) {
43
                case $child instanceof DirectiveNode:
44
                    $scalar->directives[] = $child;
45
                    break;
46
            }
47
        }
48
49
        return $scalar;
50
    }
51
}
52