InterfaceTypeExtensionNode::create()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 21
rs 9.5222
c 0
b 0
f 0
cc 5
nc 5
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\FieldDefinitionNode;
15
use Railt\SDL\Frontend\Ast\Definition\Type\ImplementedInterfaceNode;
0 ignored issues
show
Bug introduced by
The type Railt\SDL\Frontend\Ast\D...mplementedInterfaceNode 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...
16
use Railt\SDL\Frontend\Ast\Definition\Type\InterfaceTypeDefinitionNode;
17
use Railt\SDL\Frontend\Ast\Description;
18
use Railt\SDL\Frontend\Ast\Executable\DirectiveNode;
19
use Railt\SDL\Frontend\Ast\Node;
20
use Railt\SDL\Frontend\Ast\Type\NamedTypeNode;
21
22
/**
23
 * Class InterfaceTypeExtensionNode
24
 *
25
 * <code>
26
 *  export interface InterfaceTypeExtensionNode {
27
 *      readonly kind: 'InterfaceTypeExtension';
28
 *      readonly loc?: Location;
29
 *      readonly name: IdentifierNode;
30
 *      readonly interfaces?: ReadonlyArray<NamedTypeNode>;
31
 *      readonly directives?: ReadonlyArray<DirectiveNode>;
32
 *      readonly fields?: ReadonlyArray<FieldDefinitionNode>;
33
 *  }
34
 * </code>
35
 */
36
class InterfaceTypeExtensionNode extends TypeExtensionNode
37
{
38
    /**
39
     * @var ImplementedInterfaceNode[]
40
     */
41
    public array $interfaces = [];
42
43
    /**
44
     * @var FieldDefinitionNode[]
45
     */
46
    public array $fields = [];
47
48
    /**
49
     * @param array|Node[] $children
50
     * @return static
51
     */
52
    public static function create(array $children): self
53
    {
54
        $interface = new static($children[0]);
55
56
        foreach ($children as $child) {
57
            switch (true) {
58
                case $child instanceof FieldDefinitionNode:
59
                    $interface->fields[] = $child;
60
                    break;
61
62
                case $child instanceof DirectiveNode:
63
                    $interface->directives[] = $child;
64
                    break;
65
66
                case $child instanceof ImplementedInterfaceNode:
67
                    $interface->interfaces[] = $child;
68
                    break;
69
            }
70
        }
71
72
        return $interface;
73
    }
74
}
75