Completed
Push — master ( 17976d...325209 )
by Portey
07:00
created

HumanType   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 6 2
A build() 0 16 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\StarWars\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(new CharacterInterface()), [
32
                'resolve' => function ($droid) {
33
                    return StarWarsData::getFriends($droid);
34
                },
35
            ])
36
            ->addField('appearsIn', new ListType(new EpisodeEnum()))
37
            ->addField('homePlanet', TypeMap::TYPE_STRING);
38
39
        $config
40
            ->addArgument('id', TypeMap::TYPE_ID);
41
    }
42
43
    /**
44
     * @return String type name
45
     */
46
    public function getName()
47
    {
48
        return 'Human';
49
    }
50
}
51