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

DirectiveBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getArguments() 0 3 1
A getLocations() 0 11 3
A build() 0 7 1
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