Completed
Push — master ( d52ee7...e7842c )
by Alexandr
03:54
created

QueryType   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 18.87 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 5
Bugs 3 Features 0
Metric Value
wmc 6
c 5
b 3
f 0
lcom 0
cbo 9
dl 10
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 3 1
A getName() 0 4 1
B build() 10 37 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Field\Field;
12
use Youshido\GraphQL\Field\FieldFactory;
13
use Youshido\GraphQL\Type\Object\AbstractObjectType;
14
use Youshido\GraphQL\Type\Scalar\IdType;
15
16
class QueryType extends AbstractObjectType
17
{
18
19
    public function resolve($value = null, $args = [], $type = null)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
    {
21
    }
22
23
    /**
24
     * @return String type name
25
     */
26
    public function getName()
27
    {
28
        return 'Query';
29
    }
30
31
    public function build($config)
32
    {
33
        $config
34
            ->addField('hero', [
35
                'type'    => new CharacterInterface(),
36
                'args'    => [
37
                    'episode' => ['type' => new EpisodeEnum()]
38
                ],
39
                'resolve' => function ($root, $args) {
40
                    return StarWarsData::getHero(isset($args['episode']) ? $args['episode'] : null);
41
                },
42
            ])
43
            ->addField(new Field([
44
                'name'    => 'human',
45
                'type'    => new HumanType(),
46
                'args'    => [
47
                    'id' => new IdType()
48
                ],
49 View Code Duplication
                'resolve' => function ($value = null, $args = []) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
50
                    $humans = StarWarsData::humans();
51
52
                    return isset($humans[$args['id']]) ? $humans[$args['id']] : null;
53
                }
54
            ]))
55
            ->addField(new Field([
56
                'name'    => 'droid',
57
                'type'    => new DroidType(),
58
                'args'    => [
59
                    'id' => new IdType()
60
                ],
61 View Code Duplication
                'resolve' => function ($value = null, $args = []) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
62
                    $droids = StarWarsData::droids();
63
64
                    return isset($droids[$args['id']]) ? $droids[$args['id']] : null;
65
                }
66
            ]));
67
    }
68
}
69