ScalarTypeDefinitionNode   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 11
dl 0
loc 23
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\Definition\Type;
13
14
use Railt\SDL\Frontend\Ast\Description;
15
use Railt\SDL\Frontend\Ast\Executable\DirectiveNode;
16
use Railt\SDL\Frontend\Ast\Node;
17
18
/**
19
 * Class ScalarTypeDefinitionNode
20
 *
21
 * <code>
22
 *  export interface ScalarTypeDefinitionNode {
23
 *      readonly kind: 'ScalarTypeDefinition';
24
 *      readonly loc?: Location;
25
 *      readonly description?: StringValueNode;
26
 *      readonly name: IdentifierNode;
27
 *      readonly directives?: ReadonlyArray<DirectiveNode>;
28
 *  }
29
 * </code>
30
 */
31
class ScalarTypeDefinitionNode extends TypeDefinitionNode
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[1]);
40
41
        foreach ($children as $child) {
42
            switch (true) {
43
                case $child instanceof Description:
44
                    $scalar->description = $child->value;
45
                    break;
46
47
                case $child instanceof DirectiveNode:
48
                    $scalar->directives[] = $child;
49
                    break;
50
            }
51
        }
52
53
        return $scalar;
54
    }
55
}
56