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 Search |
||
| 6 | { |
||
| 7 | |||
| 8 | private $tmdb = null; |
||
| 9 | private $page = 1; // Page number of the search result |
||
| 10 | private $total_pages = 1; // Total pages of the search result |
||
| 11 | private $total_results = 0; // Total results of the search result |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Constructor |
||
| 15 | * @param \vfalies\tmdb\Tmdb $tmdb |
||
| 16 | */ |
||
| 17 | |||
| 18 | 46 | public function __construct(Tmdb $tmdb) |
|
| 22 | |||
| 23 | /** |
||
| 24 | * Search specify item |
||
| 25 | * @param string $item item to search : movie / tv / collection |
||
| 26 | * @param string $query Query string to search like a $item |
||
| 27 | * @param array $options Array of options for the request |
||
| 28 | * @param string $result_class class name of the wanted result |
||
| 29 | * @return \Generator|$result_class |
||
|
|
|||
| 30 | * @throws \Exception |
||
| 31 | */ |
||
| 32 | 43 | private function searchItem(string $item, string $query, array $options, $result_class): \Generator |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Search Item generator method |
||
| 58 | * @param array $results |
||
| 59 | * @param string $class |
||
| 60 | */ |
||
| 61 | 37 | private function searchItemGenerator(array $results, string $class): \Generator |
|
| 70 | |||
| 71 | /** |
||
| 72 | * Search a movie |
||
| 73 | * @param string $query Query string to search like a movie |
||
| 74 | * @param array $options Array of options for the search |
||
| 75 | * @return \Generator|Results\Movie |
||
| 76 | * @throws \Exception |
||
| 77 | */ |
||
| 78 | 15 | View Code Duplication | public function searchMovie(string $query, array $options = array()): \Generator |
| 89 | |||
| 90 | /** |
||
| 91 | * Search a TV Show |
||
| 92 | * @param string $query Query string to search like a TV Show |
||
| 93 | * @param array $options Array of options for the request |
||
| 94 | * @return \Generator|Results\TVShow |
||
| 95 | * @throws \Exception |
||
| 96 | */ |
||
| 97 | 14 | public function searchTVShow(string $query, array $options = array()): \Generator |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Search a collection |
||
| 111 | * @param string $query Query string to search like a collection |
||
| 112 | * @param array $options Array of option for the request |
||
| 113 | * @return \Generator|Results\Collection |
||
| 114 | * @throws \Exception |
||
| 115 | */ |
||
| 116 | 14 | View Code Duplication | public function searchCollection(string $query, array $options = array()): \Generator |
| 127 | |||
| 128 | /** |
||
| 129 | * Get movie details |
||
| 130 | * @param int $movie_id |
||
| 131 | * @param array $options |
||
| 132 | * @return \vfalies\tmdb\Movie |
||
| 133 | */ |
||
| 134 | 1 | public function getMovie(int $movie_id, array $options = array()): Movie |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Get collection details |
||
| 143 | * @param int $collection_id |
||
| 144 | * @param array $options |
||
| 145 | * @return \vfalies\tmdb\Collection |
||
| 146 | */ |
||
| 147 | 1 | public function getCollection(int $collection_id, array $options = array()): Collection |
|
| 153 | |||
| 154 | /** |
||
| 155 | * Get TV Show details |
||
| 156 | * @param int $tv_id |
||
| 157 | * @param array $options |
||
| 158 | * @return \vfalies\tmdb\TVShow |
||
| 159 | */ |
||
| 160 | 1 | public function getTVShow(int $tv_id, array $options = array()): TVShow |
|
| 166 | |||
| 167 | /** |
||
| 168 | * Get page from result search |
||
| 169 | * @return int |
||
| 170 | */ |
||
| 171 | 1 | public function getPage(): int |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Get total page from result search |
||
| 178 | * @return int |
||
| 179 | */ |
||
| 180 | 1 | public function getTotalPages(): int |
|
| 184 | |||
| 185 | /** |
||
| 186 | * Get total results from search |
||
| 187 | * @return int |
||
| 188 | */ |
||
| 189 | 1 | public function getTotalResults(): int |
|
| 193 | |||
| 194 | } |
||
| 195 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.