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 |
||
5 | class Movie implements Interfaces\MovieInterface |
||
6 | { |
||
7 | |||
8 | private $tmdb = null; |
||
9 | private $conf = null; |
||
10 | private $data = null; |
||
11 | private $id = null; |
||
12 | |||
13 | /** |
||
14 | * Constructor |
||
15 | * @param \vfalies\tmdb\Tmdb $tmdb |
||
16 | * @param int $movie_id |
||
17 | * @param array $options |
||
18 | * @throws Exception |
||
19 | */ |
||
20 | 28 | View Code Duplication | public function __construct(Tmdb $tmdb, int $movie_id, array $options = array()) |
37 | |||
38 | /** |
||
39 | * Get movie genres |
||
40 | * @return array |
||
41 | */ |
||
42 | 2 | public function getGenres(): array |
|
50 | |||
51 | /** |
||
52 | * Get movie title |
||
53 | * @return string |
||
54 | */ |
||
55 | 2 | public function getTitle(): string |
|
63 | |||
64 | /** |
||
65 | * Get movie overview |
||
66 | * @return string |
||
67 | */ |
||
68 | 2 | public function getOverview(): string |
|
76 | |||
77 | /** |
||
78 | * Get movie release date |
||
79 | * @return string |
||
80 | */ |
||
81 | 2 | public function getReleaseDate(): string |
|
89 | |||
90 | /** |
||
91 | * Get movie original title |
||
92 | * @return string |
||
93 | */ |
||
94 | 2 | public function getOriginalTitle(): string |
|
102 | |||
103 | /** |
||
104 | * Get movie note |
||
105 | * @return float |
||
106 | */ |
||
107 | 2 | public function getNote(): float |
|
115 | |||
116 | /** |
||
117 | * Get movie id |
||
118 | * @return int |
||
119 | */ |
||
120 | 1 | public function getId(): int |
|
124 | |||
125 | /** |
||
126 | * Get IMDB movie id |
||
127 | * @return string |
||
128 | */ |
||
129 | 2 | public function getIMDBId(): string |
|
137 | |||
138 | /** |
||
139 | * Get movie tagline |
||
140 | * @return string |
||
141 | */ |
||
142 | 2 | public function getTagLine(): string |
|
150 | |||
151 | /** |
||
152 | * Get collection id |
||
153 | * @return int |
||
154 | */ |
||
155 | 2 | public function getCollectionId(): int |
|
163 | |||
164 | /** |
||
165 | * Get movie poster |
||
166 | * @param string $size |
||
167 | * @return string |
||
168 | */ |
||
169 | 4 | View Code Duplication | public function getPoster(string $size = 'w185'): string |
185 | |||
186 | /** |
||
187 | * Get movie backdrop |
||
188 | * @param string $size |
||
189 | * @return string|null |
||
190 | */ |
||
191 | 4 | View Code Duplication | public function getBackdrop(string $size = 'w780'): string |
207 | |||
208 | } |
||
209 |
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.