Completed
Push — master ( 577784...c1d3e6 )
by Portey
09:27
created

QueryType::build()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 3.0015

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 25
ccs 17
cts 18
cp 0.9444
rs 8.8571
cc 3
eloc 17
nc 1
nop 1
crap 3.0015
1
<?php
2
/**
3
 * Date: 03.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Definition;
9
10
use Youshido\GraphQL\Schema;
11
use Youshido\GraphQL\Type\Config\TypeConfigInterface;
12
use Youshido\GraphQL\Type\Field\Field;
13
use Youshido\GraphQL\Type\ListType\ListType;
14
use Youshido\GraphQL\Type\Object\AbstractObjectType;
15
use Youshido\GraphQL\Type\TypeMap;
16
17
class QueryType extends AbstractObjectType
18
{
19
20 6
    protected function build(TypeConfigInterface $config)
21
    {
22
        $config
23 6
            ->addField('name', TypeMap::TYPE_STRING)
24 6
            ->addField('kind', TypeMap::TYPE_STRING)
25 6
            ->addField('description', TypeMap::TYPE_STRING)
26 6
            ->addField('ofType', new QueryListType(), [
27
                'resolve' => function () {
28 2
                    return [];
29
                }
30 6
            ])
31 6
            ->addField('inputFields', new InputValueListType())
32 6
            ->addField('enumValues', new EnumValueListType())
33 6
            ->addField('fields', new FieldListType())
34 6
            ->addField('interfaces', new InterfaceListType())
35 6
            ->addField('possibleTypes', new ListType(new QueryType()), [
36 2
                'resolve' => function($value, $args) {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37 2
                    if ($value && in_array($value->getKind(), [TypeMap::KIND_INTERFACE, TypeMap::KIND_UNION])) {
38
                        return $value->getTypes();
39
                    }
40
41 2
                    return null;
42
                }
43 6
            ]);
44 6
    }
45
46 3
    public function resolve($value = null, $args = [])
47
    {
48
        /** @var Schema|Field $value */
49 3
        if ($value instanceof Schema) {
50 3
            return $value->getQueryType();
51
        }
52
53 2
        return $value->getConfig()->getType();
54
    }
55
56
    /**
57
     * @return String type name
58
     */
59 6
    public function getName()
60
    {
61 6
        return '__Type';
62
    }
63
}