TypesField::resolve()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.7333
c 0
b 0
f 0
cc 3
nc 4
nop 3
crap 3
1
<?php
2
/**
3
 * Date: 16.05.16
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Introspection\Field;
9
10
11
use Youshido\GraphQL\Execution\ResolveInfo;
12
use Youshido\GraphQL\Field\AbstractField;
13
use Youshido\GraphQL\Introspection\QueryType;
14
use Youshido\GraphQL\Introspection\Traits\TypeCollectorTrait;
15
use Youshido\GraphQL\Schema\AbstractSchema;
16
use Youshido\GraphQL\Type\ListType\ListType;
17
use Youshido\GraphQL\Type\Object\AbstractObjectType;
18
19
class TypesField extends AbstractField
20
{
21
22
    use TypeCollectorTrait;
23
24
    /**
25
     * @return AbstractObjectType
26
     */
27 12
    public function getType()
28
    {
29 12
        return new ListType(new QueryType());
30
    }
31
32 12
    public function getName()
33
    {
34 12
        return 'types';
35
    }
36
37 7
    public function resolve($value, array $args, ResolveInfo $info)
38
    {
39
        /** @var $value AbstractSchema $a */
40 7
        $this->types = [];
41 7
        $this->collectTypes($value->getQueryType());
42
43 7
        if ($value->getMutationType()->hasFields()) {
44 3
            $this->collectTypes($value->getMutationType());
45 3
        }
46
47 7
        foreach ($value->getTypesList()->getTypes() as $type) {
48 1
          $this->collectTypes($type);
49 7
        }
50
51 7
        return array_values($this->types);
52
    }
53
54
}
55