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 declare(strict_types = 1); |
||
30 | class Movie extends Item implements MovieInterface |
||
31 | { |
||
32 | use ElementTrait; |
||
33 | |||
34 | /** |
||
35 | * Constructor |
||
36 | * @param TmdbInterface $tmdb |
||
37 | * @param int $movie_id |
||
38 | * @param array $options |
||
39 | */ |
||
40 | 120 | public function __construct(TmdbInterface $tmdb, int $movie_id, array $options = array()) |
|
46 | |||
47 | /** |
||
48 | * Get movie genres |
||
49 | * @return array |
||
50 | */ |
||
51 | 6 | public function getGenres() : array |
|
58 | |||
59 | /** |
||
60 | * Get movie title |
||
61 | * @return string |
||
62 | */ |
||
63 | 6 | public function getTitle() : string |
|
70 | |||
71 | /** |
||
72 | * Get movie overview |
||
73 | * @return string |
||
74 | */ |
||
75 | 6 | public function getOverview() : string |
|
82 | |||
83 | /** |
||
84 | * Get movie release date |
||
85 | * @return string |
||
86 | */ |
||
87 | 6 | public function getReleaseDate() : string |
|
94 | |||
95 | /** |
||
96 | * Get movie original title |
||
97 | * @return string |
||
98 | */ |
||
99 | 6 | public function getOriginalTitle() : string |
|
106 | |||
107 | /** |
||
108 | * Get movie note |
||
109 | * @return float |
||
110 | */ |
||
111 | 6 | public function getNote() : float |
|
118 | |||
119 | /** |
||
120 | * Get movie id |
||
121 | * @return int |
||
122 | */ |
||
123 | 3 | public function getId() : int |
|
127 | |||
128 | /** |
||
129 | * Get IMDB movie id |
||
130 | * @return string |
||
131 | */ |
||
132 | 6 | public function getIMDBId() : string |
|
139 | |||
140 | /** |
||
141 | * Get movie tagline |
||
142 | * @return string |
||
143 | */ |
||
144 | 6 | public function getTagLine() : string |
|
151 | |||
152 | /** |
||
153 | * Get collection id |
||
154 | * @return int |
||
155 | */ |
||
156 | 6 | public function getCollectionId() : int |
|
163 | |||
164 | /** |
||
165 | * Get movie crew |
||
166 | * @return \Generator|Results\Crew |
||
167 | */ |
||
168 | 3 | public function getCrew() : \Generator |
|
173 | |||
174 | /** |
||
175 | * Get movie cast |
||
176 | * @return \Generator|Results\Cast |
||
177 | */ |
||
178 | 27 | public function getCast() : \Generator |
|
183 | |||
184 | /** |
||
185 | * Get movie videos |
||
186 | * |
||
187 | * @return \Generator|Results\Videos |
||
188 | */ |
||
189 | 3 | public function getVideos() :\Generator |
|
194 | |||
195 | /** |
||
196 | * Get production compagnies |
||
197 | * @return \Generator|Results\Company |
||
198 | */ |
||
199 | 3 | public function getProductionCompanies() : \Generator |
|
213 | |||
214 | /** |
||
215 | * Get production countries |
||
216 | * @return \Generator|\stdClass |
||
217 | */ |
||
218 | 3 | public function getProductionCountries() : \Generator |
|
230 | |||
231 | /** |
||
232 | * Get image backdrops list |
||
233 | * @return \Generator|Results\Image |
||
234 | */ |
||
235 | 3 | View Code Duplication | public function getBackdrops() : \Generator |
246 | |||
247 | /** |
||
248 | * Get image posters list |
||
249 | * @return \Generator|Results\Image |
||
250 | */ |
||
251 | 3 | View Code Duplication | public function getPosters() : \Generator |
262 | |||
263 | /** |
||
264 | * Get similar movies from current movie |
||
265 | * @return \Generator|Results\Movie |
||
266 | */ |
||
267 | 3 | View Code Duplication | public function getSimilar() : \Generator |
279 | } |
||
280 |
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.