UnionTypeExtensionNode::create()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 17
rs 9.9332
c 0
b 0
f 0
cc 4
nc 4
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\UnionMemberNode;
0 ignored issues
show
Bug introduced by
The type Railt\SDL\Frontend\Ast\D...on\Type\UnionMemberNode was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Railt\SDL\Frontend\Ast\Definition\Type\UnionTypeDefinitionNode;
16
use Railt\SDL\Frontend\Ast\Description;
17
use Railt\SDL\Frontend\Ast\Executable\DirectiveNode;
18
use Railt\SDL\Frontend\Ast\Node;
19
use Railt\SDL\Frontend\Ast\Type\NamedTypeNode;
20
21
/**
22
 * Class UnionTypeExtensionNode
23
 *
24
 * <code>
25
 *  export interface UnionTypeExtensionNode {
26
 *      readonly kind: 'UnionTypeExtension';
27
 *      readonly loc?: Location;
28
 *      readonly name: IdentifierNode;
29
 *      readonly directives?: ReadonlyArray<DirectiveNode>;
30
 *      readonly types?: ReadonlyArray<NamedTypeNode>;
31
 *  }
32
 * </code>
33
 */
34
class UnionTypeExtensionNode extends TypeExtensionNode
35
{
36
    /**
37
     * @var UnionMemberNode[]
38
     */
39
    public array $types = [];
40
41
    /**
42
     * @param array|Node[] $children
43
     * @return static
44
     */
45
    public static function create(array $children): self
46
    {
47
        $union = new static($children[0]);
48
49
        foreach ($children as $child) {
50
            switch (true) {
51
                case $child instanceof DirectiveNode:
52
                    $union->directives[] = $child;
53
                    break;
54
55
                case $child instanceof UnionMemberNode:
56
                    $union->types[] = $child;
57
                    break;
58
            }
59
        }
60
61
        return $union;
62
    }
63
}
64