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 Genres implements Interfaces\GenresInterface |
||
6 | { |
||
7 | |||
8 | protected $tmdb = null; |
||
9 | |||
10 | /** |
||
11 | * Constructor |
||
12 | * @param \vfalies\tmdb\Tmdb $tmdb |
||
13 | * @throws Exception |
||
14 | */ |
||
15 | 5 | public function __construct(Tmdb $tmdb) |
|
19 | |||
20 | /** |
||
21 | * Get movie genres list |
||
22 | * @param array $options |
||
23 | * @return \Generator |
||
24 | * @throws \Exception |
||
25 | */ |
||
26 | 3 | View Code Duplication | public function getMovieList(array $options = array()): \Generator |
37 | |||
38 | /** |
||
39 | * Get TV genres list |
||
40 | * @param array $options |
||
41 | * @return \Generator |
||
42 | * @throws \Exception |
||
43 | */ |
||
44 | 2 | View Code Duplication | public function getTVList(array $options = array()): \Generator |
55 | |||
56 | /** |
||
57 | * Generic getter list |
||
58 | * @param string $type |
||
59 | * @param array $options |
||
60 | * @return \Generator |
||
61 | * @throws \Exception |
||
62 | */ |
||
63 | 5 | private function getList(string $type, array $options): \Generator |
|
83 | |||
84 | /** |
||
85 | * Genre Item generator method |
||
86 | * @param array $results |
||
87 | */ |
||
88 | 3 | private function genreItemGenerator(array $results): \Generator |
|
95 | |||
96 | } |
||
97 |
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.