Completed
Push — master ( 6e2397...27a4c1 )
by Beñat
04:28
created

CharacterResolver   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolveType() 0 16 3
A resolveFriends() 0 4 1
A resolveHero() 0 4 2
A resolveHuman() 0 6 2
A resolveDroid() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Kreta\AppBundle\Resolver;
14
15
use GraphQL\Tests\StarWarsData;
16
use Overblog\GraphQLBundle\Resolver\TypeResolver;
17
18
class CharacterResolver
19
{
20
    private $typeResolver;
21
22
    public function __construct(TypeResolver $typeResolver)
23
    {
24
        $this->typeResolver = $typeResolver;
25
    }
26
27
    public function resolveType($data)
28
    {
29
        $humanType = $this->typeResolver->resolve('Human');
30
        $droidType = $this->typeResolver->resolve('Droid');
31
32
        $humans = StarWarsData::humans();
33
        $droids = StarWarsData::droids();
34
        if (isset($humans[$data['id']])) {
35
            return $humanType;
36
        }
37
        if (isset($droids[$data['id']])) {
38
            return $droidType;
39
        }
40
41
        return null;
42
    }
43
44
    public function resolveFriends($character) : array
45
    {
46
        return StarWarsData::getFriends($character);
47
    }
48
49
    public function resolveHero($args)
50
    {
51
        return StarWarsData::getHero(isset($args['episode']) ? $args['episode'] : null);
52
    }
53
54
    public function resolveHuman($args)
55
    {
56
        $humans = StarWarsData::humans();
57
58
        return isset($humans[$args['id']]) ? $humans[$args['id']] : null;
59
    }
60
61
    public function resolveDroid($args)
62
    {
63
        $droids = StarWarsData::droids();
64
65
        return isset($droids[$args['id']]) ? $droids[$args['id']] : null;
66
    }
67
}
68