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

DirectiveBuilder::getLocations()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
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\Definition\Directive;
13
use GraphQL\Type\Definition\DirectiveLocation;
14
use Railt\Reflection\Contracts\Definitions\Directive\Location;
0 ignored issues
show
Bug introduced by
The type Railt\Reflection\Contrac...ions\Directive\Location 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\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...
16
17
/**
18
 * @property DirectiveDefinition $reflection
19
 */
20
class DirectiveBuilder extends TypeBuilder
21
{
22
    private const LOCATION_MAPPINGS = [
23
        Location::TARGET_QUERY               => DirectiveLocation::QUERY,
24
        Location::TARGET_MUTATION            => DirectiveLocation::MUTATION,
25
        Location::TARGET_SUBSCRIPTION        => DirectiveLocation::SUBSCRIPTION,
26
        Location::TARGET_FIELD               => DirectiveLocation::FIELD,
27
        Location::TARGET_FRAGMENT_DEFINITION => DirectiveLocation::FRAGMENT_DEFINITION,
28
        Location::TARGET_FRAGMENT_SPREAD     => DirectiveLocation::FRAGMENT_SPREAD,
29
        Location::TARGET_INLINE_FRAGMENT     => DirectiveLocation::INLINE_FRAGMENT,
30
    ];
31
32
    /**
33
     * @return Directive
34
     */
35
    public function build(): Directive
36
    {
37
        return new Directive([
38
            'name'        => $this->reflection->getName(),
39
            'description' => $this->reflection->getDescription(),
40
            'locations'   => $this->getLocations(),
41
            'args'        => [],
42
        ]);
43
    }
44
45
    /**
46
     * TODO Arguments resolve
47
     *
48
     * @return array
49
     */
50
    private function getArguments(): array
0 ignored issues
show
Unused Code introduced by
The method getArguments() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
51
    {
52
        return [];
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    private function getLocations(): array
59
    {
60
        $result = [];
61
62
        foreach ($this->reflection->getLocations() as $location) {
63
            if (\array_key_exists($location, self::LOCATION_MAPPINGS)) {
64
                $result[] = self::LOCATION_MAPPINGS[$location];
65
            }
66
        }
67
68
        return $result;
69
    }
70
}
71