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

StarWarsData   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 139
Duplicated Lines 35.25 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 15
c 1
b 1
f 1
lcom 1
cbo 0
dl 49
loc 139
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A luke() 10 10 1
A vader() 10 10 1
A han() 9 9 1
A leia() 10 10 1
A tarkin() 0 9 1
A humans() 0 10 1
A threepio() 10 10 1
A artoo() 0 11 1
A droids() 0 7 1
A getCharacter() 0 12 3
A getHero() 0 9 2
A getFriends() 0 4 1

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
class StarWarsData
12
{
13 View Code Duplication
    private static function luke()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
14
    {
15
        return [
16
            'id' => '1000',
17
            'name' => 'Luke Skywalker',
18
            'friends' => ['1002', '1003', '2000', '2001'],
19
            'appearsIn' => [4, 5, 6],
20
            'homePlanet' => 'Tatooine',
21
        ];
22
    }
23
24 View Code Duplication
    private static function vader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
25
    {
26
        return [
27
            'id' => '1001',
28
            'name' => 'Darth Vader',
29
            'friends' => ['1004'],
30
            'appearsIn' => [4, 5, 6],
31
            'homePlanet' => 'Tatooine',
32
        ];
33
    }
34
35 View Code Duplication
    private static function han()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
36
    {
37
        return [
38
            'id' => '1002',
39
            'name' => 'Han Solo',
40
            'friends' => ['1000', '1003', '2001'],
41
            'appearsIn' => [4, 5, 6],
42
        ];
43
    }
44
45 View Code Duplication
    private static function leia()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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
    {
47
        return [
48
            'id' => '1003',
49
            'name' => 'Leia Organa',
50
            'friends' => ['1000', '1002', '2000', '2001'],
51
            'appearsIn' => [4, 5, 6],
52
            'homePlanet' => 'Alderaan',
53
        ];
54
    }
55
56
    private static function tarkin()
57
    {
58
        return [
59
            'id' => '1004',
60
            'name' => 'Wilhuff Tarkin',
61
            'friends' => ['1001'],
62
            'appearsIn' => [4],
63
        ];
64
    }
65
66
    static function humans()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
67
    {
68
        return [
69
            '1000' => self::luke(),
70
            '1001' => self::vader(),
71
            '1002' => self::han(),
72
            '1003' => self::leia(),
73
            '1004' => self::tarkin(),
74
        ];
75
    }
76
77 View Code Duplication
    private static function threepio()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
78
    {
79
        return [
80
            'id' => '2000',
81
            'name' => 'C-3PO',
82
            'friends' => ['1000', '1002', '1003', '2001'],
83
            'appearsIn' => [4, 5, 6],
84
            'primaryFunction' => 'Protocol',
85
        ];
86
    }
87
88
    /**
89
     * We export artoo directly because the schema returns him
90
     * from a root field, and hence needs to reference him.
91
     */
92
    static function artoo()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
93
    {
94
        return [
95
96
            'id' => '2001',
97
            'name' => 'R2-D2',
98
            'friends' => ['1000', '1002', '1003'],
99
            'appearsIn' => [4, 5, 6],
100
            'primaryFunction' => 'Astromech',
101
        ];
102
    }
103
104
    static function droids()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
105
    {
106
        return [
107
            '2000' => self::threepio(),
108
            '2001' => self::artoo(),
109
        ];
110
    }
111
112
    /**
113
     * Helper function to get a character by ID.
114
     */
115
    static function getCharacter($id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
116
    {
117
        $humans = self::humans();
118
        $droids = self::droids();
119
        if (isset($humans[$id])) {
120
            return $humans[$id];
121
        }
122
        if (isset($droids[$id])) {
123
            return $droids[$id];
124
        }
125
        return null;
126
    }
127
128
    /**
129
     * @param $episode
130
     * @return array
131
     */
132
    static function getHero($episode)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
133
    {
134
        if ($episode === 5) {
135
            // Luke is the hero of Episode V.
136
            return self::luke();
137
        }
138
        // Artoo is the hero otherwise.
139
        return self::artoo();
140
    }
141
142
    /**
143
     * Allows us to query for a character's friends.
144
     */
145
    static function getFriends($character)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
146
    {
147
        return array_map([__CLASS__, 'getCharacter'], $character['friends']);
148
    }
149
}