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 |
||
| 9 | class Genres implements GenresInterface |
||
| 10 | { |
||
| 11 | |||
| 12 | protected $tmdb = null; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Constructor |
||
| 16 | * @param \vfalies\tmdb\Tmdb $tmdb |
||
| 17 | * @throws Exception |
||
| 18 | */ |
||
| 19 | 5 | public function __construct(Tmdb $tmdb) |
|
| 23 | |||
| 24 | /** |
||
| 25 | * Get movie genres list |
||
| 26 | * @param array $options |
||
| 27 | * @return \Generator |
||
| 28 | * @throws \Exception |
||
| 29 | */ |
||
| 30 | 3 | View Code Duplication | public function getMovieList(array $options = array()): \Generator |
| 40 | |||
| 41 | /** |
||
| 42 | * Get TV genres list |
||
| 43 | * @param array $options |
||
| 44 | * @return \Generator |
||
| 45 | * @throws \Exception |
||
| 46 | */ |
||
| 47 | 2 | View Code Duplication | public function getTVList(array $options = array()): \Generator |
| 57 | |||
| 58 | /** |
||
| 59 | * Generic getter list |
||
| 60 | * @param string $type |
||
| 61 | * @param array $options |
||
| 62 | * @return \Generator |
||
| 63 | * @throws \Exception |
||
| 64 | */ |
||
| 65 | 5 | private function getList(string $type, array $options): \Generator |
|
| 84 | |||
| 85 | /** |
||
| 86 | * Genre Item generator method |
||
| 87 | * @param array $results |
||
| 88 | */ |
||
| 89 | 3 | private function genreItemGenerator(array $results): \Generator |
|
| 96 | |||
| 97 | } |
||
| 98 |