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

DroidType   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A build() 0 11 1
A resolve() 0 6 2
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 DroidType extends HumanType
17
{
18
19
    /**
20
     * @return String type name
21
     */
22
    public function getName()
23
    {
24
        return 'Droid';
25
    }
26
27
    protected function build(TypeConfigInterface $config)
28
    {
29
        parent::build($config);
30
31
        $config->getField('friends')->getConfig()->set('resolve', function($droid){
0 ignored issues
show
Documentation Bug introduced by
The method getConfig does not exist on object<Youshido\GraphQL\...nfig\Field\FieldConfig>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
32
            return StarWarsData::getFriends($droid);
33
        });
34
35
        $config
36
            ->addField('primaryFunction', TypeMap::TYPE_STRING);
37
    }
38
39
    public function resolve($value = null, $args = [])
40
    {
41
        $droids = StarWarsData::droids();
42
43
        return isset($droids[$args['id']]) ? $droids[$args['id']] : null;
44
    }
45
46
47
}