StarWarsQueryType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 20.41 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 9
dl 10
loc 49
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A 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 StarWarsQueryType extends AbstractObjectType
17
{
18
19
    /**
20
     * @return String type name
21
     */
22
    public function getName()
23
    {
24
        return 'Query';
25
    }
26
27
    public function build($config)
28
    {
29
        $config
30
            ->addField('hero', [
31
                'type'    => new CharacterInterface(),
32
                'args'    => [
33
                    'episode' => ['type' => new EpisodeEnum()]
34
                ],
35
                'resolve' => function ($root, $args) {
36
                    return StarWarsData::getHero(isset($args['episode']) ? $args['episode'] : null);
37
                },
38
            ])
39
            ->addField(new Field([
40
                'name'    => 'human',
41
                'type'    => new HumanType(),
42
                'args'    => [
43
                    'id' => new IdType()
44
                ],
45 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...
46
                    $humans = StarWarsData::humans();
47
48
                    return isset($humans[$args['id']]) ? $humans[$args['id']] : null;
49
                }
50
            ]))
51
            ->addField(new Field([
52
                'name'    => 'droid',
53
                'type'    => new DroidType(),
54
                'args'    => [
55
                    'id' => new IdType()
56
                ],
57 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...
58
                    $droids = StarWarsData::droids();
59
60
                    return isset($droids[$args['id']]) ? $droids[$args['id']] : null;
61
                }
62
            ]));
63
    }
64
}
65