Completed
Push — master ( d01340...7e7fa7 )
by Portey
07:36
created

CharacterInterface::resolveType()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
rs 9.4286
cc 3
eloc 8
nc 3
nop 1
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\Schema;
10
11
12
use Youshido\GraphQL\Type\Config\Object\InterfaceTypeConfig;
13
use Youshido\GraphQL\Type\ListType\ListType;
14
use Youshido\GraphQL\Type\Object\AbstractInterfaceType;
15
use Youshido\GraphQL\Type\TypeMap;
16
17
class CharacterInterface extends AbstractInterfaceType
18
{
19
    protected function build(InterfaceTypeConfig $config)
20
    {
21
        $config
22
            ->addField('id', TypeMap::TYPE_ID, ['required' => true])
23
            ->addField('name', TypeMap::TYPE_STRING, ['required' => true])
24
            ->addField('friends', new ListType(['item' => new CharacterInterface()]), [
25
                'resolve' => function($value){
26
                    return $value['friends'];
27
                }
28
            ])
29
            ->addField('appearsIn', new ListType(['item' => new EpisodeEnum()]));
30
    }
31
32
    public function getDescription()
33
    {
34
        return 'A character in the Star Wars Trilogy';
35
    }
36
37
    public function getName()
38
    {
39
        return 'Character';
40
    }
41
42 View Code Duplication
    public function resolveType($object)
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...
43
    {
44
        $humans = StarWarsData::humans();
45
        $droids = StarWarsData::droids();
46
47
        if (isset($humans[$object])) {
48
            return $humans[$object];
49
        }
50
        if (isset($droids[$object])) {
51
            return $droids[$object];
52
        }
53
54
        return null;
55
    }
56
57
}