TypesField::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
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