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 |
||
26 | View Code Duplication | class Cast extends Results implements CastResultsInterface |
|
|
|||
27 | { |
||
28 | /** |
||
29 | * Character name |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $character = null; |
||
33 | /** |
||
34 | * Gender |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $gender = null; |
||
38 | /** |
||
39 | * Credit Id |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $credit_id = null; |
||
43 | /** |
||
44 | * Cast Id |
||
45 | * @var int |
||
46 | */ |
||
47 | protected $cast_id = null; |
||
48 | /** |
||
49 | * Name |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $name = null; |
||
53 | /** |
||
54 | * Image profile path |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $profile_path = null; |
||
58 | /** |
||
59 | * Order in cast |
||
60 | * @var int |
||
61 | */ |
||
62 | protected $order = null; |
||
63 | /** |
||
64 | * Id |
||
65 | * @var int |
||
66 | */ |
||
67 | protected $id = null; |
||
68 | |||
69 | /** |
||
70 | * Constructor |
||
71 | * @param \vfalies\tmdb\Interfaces\TmdbInterface $tmdb |
||
72 | * @param \stdClass $result |
||
73 | */ |
||
74 | 11 | public function __construct(TmdbInterface $tmdb, \stdClass $result) |
|
87 | |||
88 | /** |
||
89 | * Get Id |
||
90 | * @return int |
||
91 | */ |
||
92 | 3 | public function getId() |
|
96 | |||
97 | /** |
||
98 | * Get credit Id |
||
99 | * @return string |
||
100 | */ |
||
101 | 1 | public function getCreditId() |
|
105 | |||
106 | /** |
||
107 | * Get character name |
||
108 | * @return string |
||
109 | */ |
||
110 | 1 | public function getCharacter() |
|
114 | |||
115 | /** |
||
116 | * Get gender |
||
117 | * @return string |
||
118 | */ |
||
119 | 1 | public function getGender() |
|
123 | |||
124 | /** |
||
125 | * Get Cast Id |
||
126 | * @return int |
||
127 | */ |
||
128 | 1 | public function getCastId() |
|
132 | |||
133 | /** |
||
134 | * Get name |
||
135 | * @return string |
||
136 | */ |
||
137 | 1 | public function getName() |
|
141 | |||
142 | /** |
||
143 | * Get profile path |
||
144 | * @return string |
||
145 | */ |
||
146 | 1 | public function getProfilePath() |
|
150 | |||
151 | /** |
||
152 | * Get Order |
||
153 | * @return int |
||
154 | */ |
||
155 | 1 | public function getOrder() |
|
159 | |||
160 | } |
||
161 |
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.