StarWarsQueryType::build()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 37

Duplication

Lines 10
Ratio 27.03 %

Importance

Changes 0
Metric Value
dl 10
loc 37
rs 9.328
c 0
b 0
f 0
cc 4
nc 1
nop 1
1
<?php
2
/**
3
 * Date: 07.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\Tests\StarWars\Schema;
9
10
11
use Youshido\GraphQL\Field\Field;
12
use Youshido\GraphQL\Field\FieldFactory;
13
use Youshido\GraphQL\Type\Object\AbstractObjectType;
14
use Youshido\GraphQL\Type\Scalar\IdType;
15
16
class StarWarsQueryType extends AbstractObjectType
17
{
18
19
    /**
20
     * @return String type name
21
     */
22
    public function getName()
23
    {
24
        return 'Query';
25
    }
26
27
    public function build($config)
28
    {
29
        $config
30
            ->addField('hero', [
31
                'type'    => new CharacterInterface(),
32
                'args'    => [
33
                    'episode' => ['type' => new EpisodeEnum()]
34
                ],
35
                'resolve' => function ($root, $args) {
36
                    return StarWarsData::getHero(isset($args['episode']) ? $args['episode'] : null);
37
                },
38
            ])
39
            ->addField(new Field([
40
                'name'    => 'human',
41
                'type'    => new HumanType(),
42
                'args'    => [
43
                    'id' => new IdType()
44
                ],
45 View Code Duplication
                'resolve' => function ($value = null, $args = []) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
                    $humans = StarWarsData::humans();
47
48
                    return isset($humans[$args['id']]) ? $humans[$args['id']] : null;
49
                }
50
            ]))
51
            ->addField(new Field([
52
                'name'    => 'droid',
53
                'type'    => new DroidType(),
54
                'args'    => [
55
                    'id' => new IdType()
56
                ],
57 View Code Duplication
                'resolve' => function ($value = null, $args = []) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
                    $droids = StarWarsData::droids();
59
60
                    return isset($droids[$args['id']]) ? $droids[$args['id']] : null;
61
                }
62
            ]));
63
    }
64
}
65