CharacterInterface::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 12/6/15 11:15 PM
7
*/
8
9
namespace Youshido\Tests\StarWars\Schema;
10
11
use Youshido\GraphQL\Type\InterfaceType\AbstractInterfaceType;
12
use Youshido\GraphQL\Type\ListType\ListType;
13
use Youshido\GraphQL\Type\NonNullType;
14
use Youshido\GraphQL\Type\Scalar\IdType;
15
use Youshido\GraphQL\Type\Scalar\StringType;
16
17
class CharacterInterface extends AbstractInterfaceType
18
{
19 View Code Duplication
    public function build($config)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
20
    {
21
        $config
22
            ->addField('id', new NonNullType(new IdType()))
23
            ->addField('name', new NonNullType(new StringType()))
24
            ->addField('friends', [
25
                'type'    => new ListType(new CharacterInterface()),
26
                'resolve' => function ($value) {
27
                    return $value['friends'];
28
                }
29
            ])
30
            ->addField('appearsIn', new ListType(new EpisodeEnum()));
31
    }
32
33
    public function getDescription()
34
    {
35
        return 'A character in the Star Wars Trilogy';
36
    }
37
38
    public function getName()
39
    {
40
        return 'Character';
41
    }
42
43
    public function resolveType($object)
44
    {
45
        $humans = StarWarsData::humans();
46
        $droids = StarWarsData::droids();
47
48
        $id = isset($object['id']) ? $object['id'] : $object;
49
50
        if (isset($humans[$id])) {
51
            return new HumanType();
52
        }
53
54
        if (isset($droids[$id])) {
55
            return new DroidType();
56
        }
57
58
        return null;
59
    }
60
61
}
62