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); |
||
29 | class TVShow extends Item implements TVShowInterface |
||
30 | { |
||
31 | use ElementTrait; |
||
32 | |||
33 | /** |
||
34 | * Constructor |
||
35 | * @param TmdbInterface $tmdb |
||
36 | * @param int $tv_id |
||
37 | * @param array $options |
||
38 | */ |
||
39 | 34 | public function __construct(TmdbInterface $tmdb, int $tv_id, array $options = array()) |
|
45 | |||
46 | /** |
||
47 | * Get TV show id |
||
48 | * @return int |
||
49 | */ |
||
50 | 1 | public function getId() : int |
|
54 | |||
55 | /** |
||
56 | * Get TVSHow genres |
||
57 | * @return array |
||
58 | */ |
||
59 | 2 | public function getGenres() : array |
|
66 | |||
67 | /** |
||
68 | * Get TVshow note |
||
69 | * @return float |
||
70 | */ |
||
71 | 2 | public function getNote() : float |
|
78 | |||
79 | /** |
||
80 | * Get TVshow number of episodes |
||
81 | * @return int |
||
82 | */ |
||
83 | 2 | public function getNumberEpisodes() : int |
|
90 | |||
91 | /** |
||
92 | * Get TVShow number of seasons |
||
93 | * @return int |
||
94 | */ |
||
95 | 2 | public function getNumberSeasons() : int |
|
102 | |||
103 | /** |
||
104 | * Get TVShow original title |
||
105 | * @return string |
||
106 | */ |
||
107 | 2 | public function getOriginalTitle() : string |
|
114 | |||
115 | /** |
||
116 | * Get TVShow overview |
||
117 | * @return string |
||
118 | */ |
||
119 | 2 | public function getOverview() : string |
|
126 | |||
127 | /** |
||
128 | * Get TVShow release date |
||
129 | * @return string |
||
130 | */ |
||
131 | 2 | public function getReleaseDate() : string |
|
138 | |||
139 | /** |
||
140 | * Get TVShow status |
||
141 | * @return string |
||
142 | */ |
||
143 | 2 | public function getStatus() : string |
|
150 | |||
151 | /** |
||
152 | * Get TVShow title |
||
153 | * @return string |
||
154 | */ |
||
155 | 2 | public function getTitle() : string |
|
162 | |||
163 | /** |
||
164 | * Get TVShow seasons |
||
165 | * @return \Generator|Results\TVSeason |
||
166 | */ |
||
167 | 6 | public function getSeasons() : \Generator |
|
176 | |||
177 | /** |
||
178 | * Get TVShow networks |
||
179 | * @return \Generator|\stdClass |
||
180 | */ |
||
181 | 1 | public function getNetworks() : \Generator |
|
193 | |||
194 | /** |
||
195 | * Backdrops list |
||
196 | * @return \Generator|Results\Image |
||
197 | */ |
||
198 | 1 | View Code Duplication | public function getBackdrops() : \Generator |
209 | |||
210 | /** |
||
211 | * Posters list |
||
212 | * @return \Generator|Results\Image |
||
213 | */ |
||
214 | 1 | View Code Duplication | public function getPosters() : \Generator |
225 | |||
226 | /** |
||
227 | * Get Similar TVShow |
||
228 | * @return \Generator|Results\TVShow |
||
229 | */ |
||
230 | 1 | View Code Duplication | public function getSimilar() : \Generator |
242 | } |
||
243 |
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.