Completed
Push — master ( 631929...5231d5 )
by Alexandr
02:39
created

DirectiveType   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 8
dl 0
loc 50
ccs 12
cts 20
cp 0.6
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A resolveArgs() 0 8 2
A resolveLocations() 0 9 1
A build() 0 14 1
1
<?php
2
/**
3
 * Date: 16.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Introspection;
9
10
use Youshido\GraphQL\Config\Directive\DirectiveConfig;
11
use Youshido\GraphQL\Directive\Directive;
12
use Youshido\GraphQL\Directive\DirectiveInterface;
13
use Youshido\GraphQL\Type\ListType\ListType;
14
use Youshido\GraphQL\Type\NonNullType;
15
use Youshido\GraphQL\Type\Object\AbstractObjectType;
16
use Youshido\GraphQL\Type\TypeMap;
17
18
class DirectiveType extends AbstractObjectType
19
{
20
21
    /**
22
     * @return String type name
23
     */
24 9
    public function getName()
25
    {
26 9
        return '__Directive';
27
    }
28
29
    public function resolveArgs(DirectiveInterface $value)
30
    {
31
        if ($value->hasArguments()) {
32
            return $value->getArguments();
33
        }
34
35
        return [];
36
    }
37
38
    /**
39
     * @param DirectiveInterface|Directive $value
40
     *
41
     * @return mixed
42
     */
43
    public function resolveLocations(DirectiveInterface $value)
44
    {
45
        /** @var DirectiveConfig $directiveConfig */
46
        $directiveConfig = $value->getConfig();
47
48
        $locations = $directiveConfig->getLocations();
49
50
        return $locations;
51
    }
52
53 6
    public function build($config)
54
    {
55
        $config
56 6
            ->addField('name', new NonNullType(TypeMap::TYPE_STRING))
57 6
            ->addField('description', TypeMap::TYPE_STRING)
58 6
            ->addField('args', [
59 6
                'type'    => new NonNullType(new ListType(new NonNullType(new InputValueType()))),
60 6
                'resolve' => [$this, 'resolveArgs'],
61
            ])
62 6
            ->addField('locations',[
63 6
                'type'  =>  new NonNullType(new ListType(new NonNullType(new DirectiveLocationType()))),
64 6
                'resolve' => [$this, 'resolveLocations'],
65
            ]);
66 6
    }
67
}
68