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); |
||
31 | class People extends Item implements PeopleInterface |
||
32 | { |
||
33 | use ElementTrait; |
||
34 | |||
35 | /** |
||
36 | * Constructor |
||
37 | * @param TmdbInterface $tmdb |
||
38 | * @param int $people_id |
||
39 | * @param array $options |
||
40 | * @throws TmdbException |
||
41 | */ |
||
42 | 67 | public function __construct(TmdbInterface $tmdb, int $people_id, array $options = array()) |
|
48 | |||
49 | /** |
||
50 | * Adult |
||
51 | * @return bool |
||
52 | */ |
||
53 | 2 | public function getAdult() : bool |
|
60 | |||
61 | /** |
||
62 | * Alse Known as |
||
63 | * @return array |
||
64 | */ |
||
65 | 2 | public function getAlsoKnownAs() : array |
|
72 | |||
73 | /** |
||
74 | * Biography |
||
75 | * @return string |
||
76 | */ |
||
77 | 2 | public function getBiography() : string |
|
84 | |||
85 | /** |
||
86 | * Birthday |
||
87 | * @return string |
||
88 | */ |
||
89 | 2 | public function getBirthday() : string |
|
96 | |||
97 | /** |
||
98 | * Deathday |
||
99 | * @return string |
||
100 | */ |
||
101 | 2 | public function getDeathday() : string |
|
108 | |||
109 | /** |
||
110 | * Gender |
||
111 | * @return int |
||
112 | */ |
||
113 | 2 | public function getGender() : int |
|
120 | |||
121 | /** |
||
122 | * Homepage |
||
123 | * @return string |
||
124 | */ |
||
125 | 2 | public function getHomepage() : string |
|
132 | |||
133 | /** |
||
134 | * Id |
||
135 | * @return int |
||
136 | */ |
||
137 | 3 | public function getId() : int |
|
144 | |||
145 | /** |
||
146 | * Imdb Id |
||
147 | * @return string |
||
148 | */ |
||
149 | 2 | public function getImdbId() : string |
|
156 | |||
157 | /** |
||
158 | * Name |
||
159 | * @return string |
||
160 | */ |
||
161 | 2 | public function getName() : string |
|
168 | |||
169 | /** |
||
170 | * Place of birth |
||
171 | * @return string |
||
172 | */ |
||
173 | 2 | public function getPlaceOfBirth() : string |
|
180 | |||
181 | /** |
||
182 | * Popularity |
||
183 | * @return float |
||
184 | */ |
||
185 | 2 | public function getPopularity() : float |
|
192 | |||
193 | /** |
||
194 | * Image profile path |
||
195 | * @return string |
||
196 | */ |
||
197 | 2 | public function getProfilePath() : string |
|
204 | |||
205 | /** |
||
206 | * Images Profiles |
||
207 | * @return \Generator|Results\Image |
||
208 | */ |
||
209 | 1 | View Code Duplication | public function getProfiles() : \Generator |
220 | |||
221 | /** |
||
222 | * Get movies cast |
||
223 | * @return \Generator|Results\PeopleMovieCast |
||
224 | */ |
||
225 | 9 | public function getMoviesCast() : \Generator |
|
230 | |||
231 | /** |
||
232 | * Get movies crew |
||
233 | * @return \Generator|Results\PeopleMovieCast |
||
234 | */ |
||
235 | 10 | public function getMoviesCrew() : \Generator |
|
240 | |||
241 | |||
242 | /** |
||
243 | * Get TVShow cast |
||
244 | * @return \Generator|Results\PeopleTVShowCast |
||
245 | */ |
||
246 | 9 | public function getTVShowCast() : \Generator |
|
251 | |||
252 | /** |
||
253 | * Get TVShow crew |
||
254 | * @return \Generator|Results\PeopleTVShowCast |
||
255 | */ |
||
256 | 10 | public function getTVShowCrew() : \Generator |
|
261 | } |
||
262 |
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.