ObjectTypeDefinitionNode::create()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 25
rs 9.1111
c 0
b 0
f 0
cc 6
nc 6
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\Definition\Type;
13
14
use Railt\SDL\Frontend\Ast\Definition\FieldDefinitionNode;
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 ObjectTypeDefinitionNode
21
 *
22
 * <code>
23
 *  export interface ObjectTypeDefinitionNode {
24
 *      readonly kind: 'ObjectTypeDefinition';
25
 *      readonly loc?: Location;
26
 *      readonly description?: StringValueNode;
27
 *      readonly name: IdentifierNode;
28
 *      readonly interfaces?: ReadonlyArray<NamedTypeNode>;
29
 *      readonly directives?: ReadonlyArray<DirectiveNode>;
30
 *      readonly fields?: ReadonlyArray<FieldDefinitionNode>;
31
 *  }
32
 * </code>
33
 */
34
class ObjectTypeDefinitionNode extends TypeDefinitionNode
35
{
36
    /**
37
     * @var ImplementedInterfaceNode[]
38
     */
39
    public array $interfaces = [];
40
41
    /**
42
     * @var FieldDefinitionNode[]
43
     */
44
    public array $fields = [];
45
46
    /**
47
     * @param array|Node[] $children
48
     * @return static
49
     */
50
    public static function create(array $children): self
51
    {
52
        $object = new static($children[1]);
53
54
        foreach ($children as $child) {
55
            switch (true) {
56
                case $child instanceof Description:
57
                    $object->description = $child->value;
58
                    break;
59
60
                case $child instanceof FieldDefinitionNode:
61
                    $object->fields[] = $child;
62
                    break;
63
64
                case $child instanceof DirectiveNode:
65
                    $object->directives[] = $child;
66
                    break;
67
68
                case $child instanceof 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...
69
                    $object->interfaces[] = $child;
70
                    break;
71
            }
72
        }
73
74
        return $object;
75
    }
76
}
77