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 |
||
| 27 | class Manga extends API { |
||
| 28 | |||
| 29 | const READING = 'Reading'; |
||
| 30 | const PLAN_TO_READ = 'Plan to Read'; |
||
| 31 | const DROPPED = 'Dropped'; |
||
| 32 | const ON_HOLD = 'On Hold'; |
||
| 33 | const COMPLETED = 'Completed'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Map API constants to display constants |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | protected $const_map = [ |
||
| 40 | MangaReadingStatus::READING => self::READING, |
||
| 41 | MangaReadingStatus::PLAN_TO_READ => self::PLAN_TO_READ, |
||
| 42 | MangaReadingStatus::ON_HOLD => self::ON_HOLD, |
||
| 43 | MangaReadingStatus::DROPPED => self::DROPPED, |
||
| 44 | MangaReadingStatus::COMPLETED => self::COMPLETED |
||
| 45 | ]; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * The base url for api requests |
||
| 49 | * @var string |
||
| 50 | */ |
||
| 51 | protected $base_url = "https://hummingbird.me/"; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Make an authenticated manga API call |
||
| 55 | * |
||
| 56 | * @param string $type - the HTTP verb |
||
| 57 | * @param string $url |
||
| 58 | * @param string|null $json |
||
| 59 | * @return array |
||
| 60 | */ |
||
| 61 | protected function _manga_api_call($type, $url, $json = NULL) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Add a manga to the list |
||
| 95 | * |
||
| 96 | * @param array $data |
||
| 97 | */ |
||
| 98 | public function add($data) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Update the selected manga |
||
| 112 | * |
||
| 113 | * @param array $data |
||
| 114 | * @return array |
||
| 115 | */ |
||
| 116 | public function update($data) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Delete a manga entry |
||
| 129 | * |
||
| 130 | * @param array $data |
||
| 131 | * @return array |
||
| 132 | */ |
||
| 133 | public function delete($data) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Search for manga by name |
||
| 142 | * |
||
| 143 | * @param string $name |
||
| 144 | * @return array |
||
| 145 | */ |
||
| 146 | public function search($name) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Get the full set of anime lists |
||
| 173 | * |
||
| 174 | * @return array |
||
| 175 | */ |
||
| 176 | public function get_all_lists() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Get a category out of the full list |
||
| 190 | * |
||
| 191 | * @param string $status |
||
| 192 | * @return array |
||
| 193 | */ |
||
| 194 | public function get_list($status) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Retrieve the list from the hummingbird api |
||
| 204 | * |
||
| 205 | * @param string $status |
||
| 206 | * @return array |
||
| 207 | */ |
||
| 208 | protected function _get_list_from_api($status = "All") |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Check the status of the cache and return the appropriate response |
||
| 228 | * |
||
| 229 | * @param \GuzzleHttp\Message\Response $response |
||
| 230 | * @codeCoverageIgnore |
||
| 231 | * @return array |
||
| 232 | */ |
||
| 233 | private function transform($response) |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Map transformed anime data to be organized by reading status |
||
| 250 | * |
||
| 251 | * @param array $data |
||
| 252 | * @return array |
||
| 253 | */ |
||
| 254 | private function map_by_status($data) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Combine the two manga lists into one |
||
| 280 | * @param array $raw_data |
||
| 281 | * @return array |
||
| 282 | */ |
||
| 283 | private function zipper_lists($raw_data) |
||
| 287 | } |
||
| 288 | // End of MangaModel.php |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: