Completed
Push — master ( d52ee7...e7842c )
by Alexandr
03:54
created

FieldType::build()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 6
Bugs 2 Features 1
Metric Value
c 6
b 2
f 1
dl 0
loc 24
rs 8.9713
ccs 17
cts 17
cp 1
cc 2
eloc 16
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Date: 03.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Introspection;
9
10
use Youshido\GraphQL\Field\AbstractField;
11
use Youshido\GraphQL\Type\ListType\ListType;
12
use Youshido\GraphQL\Type\Object\AbstractObjectType;
13
use Youshido\GraphQL\Type\TypeMap;
14
15
class FieldType extends AbstractObjectType
16
{
17
18 6
    public function build($config)
19
    {
20
        $config
21 6
            ->addField('name', TypeMap::TYPE_STRING)
22 6
            ->addField('description', TypeMap::TYPE_STRING)
23 6
            ->addField('isDeprecated', TypeMap::TYPE_BOOLEAN)
24 6
            ->addField('deprecationReason', TypeMap::TYPE_STRING)
25 6
            ->addField('type', [
26 6
                'type'    => new QueryType(),
27
                'resolve' => function (AbstractField $value) {
28 3
                    return $value->getType()->getNamedType();
29
                }
30 6
            ])
31 6
            ->addField('args', [
32 6
                'type'    => new ListType(new InputValueType()),
33 2
                'resolve' => function (AbstractField $value) {
34 2
                    if ($value->getConfig()->hasArguments()) {
35 2
                        return $value->getConfig()->getArguments();
36
                    }
37
38 2
                    return [];
39
                }
40 6
            ]);
41 6
    }
42
43 4
    public function isValidValue($value)
44
    {
45 4
        return $value instanceof AbstractField;
46
    }
47
48
    /**
49
     * @return String type name
50
     */
51 7
    public function getName()
52
    {
53 7
        return '__Field';
54
    }
55
}
56