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

HumanType   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 6
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 6 2
A build() 0 20 1
A getName() 0 4 1
1
<?php
2
/**
3
 * Date: 07.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\Tests\Schema;
9
10
11
use Youshido\GraphQL\Type\Config\TypeConfigInterface;
12
use Youshido\GraphQL\Type\ListType\ListType;
13
use Youshido\GraphQL\Type\Object\AbstractObjectType;
14
use Youshido\GraphQL\Type\TypeMap;
15
16
class HumanType extends AbstractObjectType
17
{
18
19
    public function resolve($value = null, $args = [])
20
    {
21
        $humans = StarWarsData::humans();
22
23
        return isset($humans[$args['id']]) ? $humans[$args['id']] : null;
24
    }
25
26
    protected function build(TypeConfigInterface $config)
27
    {
28
        $config
29
            ->addField('id', TypeMap::TYPE_ID)
30
            ->addField('name', TypeMap::TYPE_STRING)
31
            ->addField('friends', new ListType([
32
                'item' => new CharacterInterface()
33
            ]), [
34
                'resolve' => function ($droid) {
35
                    return StarWarsData::getFriends($droid);
36
                },
37
            ])
38
            ->addField('appearsIn', new ListType([
39
                'item' => new EpisodeEnum()
40
            ]))
41
            ->addField('homePlanet', TypeMap::TYPE_STRING);
42
43
        $config
44
            ->addArgument('id', TypeMap::TYPE_ID);
45
    }
46
47
    /**
48
     * @return String type name
49
     */
50
    public function getName()
51
    {
52
        return 'Human';
53
    }
54
}