Completed
Push — master ( 3b79f3...426227 )
by Kirill
03:11
created

SchemaBuilder::buildMutation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Adapters\Webonyx\Builders;
11
12
use GraphQL\Type\Schema;
0 ignored issues
show
Bug introduced by
The type GraphQL\Type\Schema 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...
13
use Railt\Compiler\Reflection\CompilerInterface;
0 ignored issues
show
Bug introduced by
The type Railt\Compiler\Reflection\CompilerInterface 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...
14
use Railt\Reflection\Contracts\Definitions\DirectiveDefinition;
0 ignored issues
show
Bug introduced by
The type Railt\Reflection\Contrac...ons\DirectiveDefinition 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\Reflection\Contracts\Definitions\SchemaDefinition;
0 ignored issues
show
Bug introduced by
The type Railt\Reflection\Contrac...itions\SchemaDefinition 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
17
/**
18
 * Class SchemaBuilder
19
 * @property SchemaDefinition $reflection
20
 */
21
class SchemaBuilder extends TypeBuilder
22
{
23
    /**
24
     * @return Schema
25
     */
26
    public function build(): Schema
27
    {
28
        $schema = \array_merge(
29
            $this->buildQuery(),
30
            $this->buildMutation(),
31
            $this->buildSubscription(),
32
            $this->buildDirectives()
33
        );
34
35
        return new Schema($schema);
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    private function buildQuery(): array
42
    {
43
        $query = $this->reflection->getQuery();
44
45
        return [
46
            'query' => $this->load($query),
47
        ];
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    private function buildMutation(): array
54
    {
55
        if ($this->reflection->hasMutation()) {
56
            $mutation = $this->reflection->getMutation();
57
58
            return [
59
                'mutation' => $this->load($mutation),
60
            ];
61
        }
62
63
        return [];
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    private function buildSubscription(): array
70
    {
71
        if ($this->reflection->hasSubscription()) {
72
            $subscription = $this->reflection->getSubscription();
73
74
            return [
75
                'subscription' => $this->load($subscription),
76
            ];
77
        }
78
79
        return [];
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    private function buildDirectives(): array
86
    {
87
        /** @var CompilerInterface $compiler */
88
        $compiler = $this->getRegistry()->getContainer()->make(CompilerInterface::class);
89
90
        $result = [];
91
92
        /** @var DirectiveDefinition $directive */
93
        foreach ($compiler->only(DirectiveDefinition::class) as $directive) {
94
            if ($directive->isAllowedForQueries()) {
95
                $result[] = $this->load($directive);
96
            }
97
        }
98
99
        return [
100
            'directives' => $result,
101
        ];
102
    }
103
}
104