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 |
||
| 14 | class Album extends AbstractApi |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var AlbumMapper |
||
| 18 | */ |
||
| 19 | protected $albumMapper; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Album constructor. |
||
| 23 | * @param HttpClientInterface $httpClient |
||
| 24 | * @param AlbumMapper $albumMapper |
||
| 25 | */ |
||
| 26 | public function __construct(HttpClientInterface $httpClient, AlbumMapper $albumMapper) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Get information about a specific album |
||
| 34 | * |
||
| 35 | * @param $id |
||
| 36 | * @return AlbumInterface |
||
| 37 | */ |
||
| 38 | public function get($id) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Create a new album |
||
| 51 | * |
||
| 52 | * @param array $ids Ids of the images you want to add to the album |
||
| 53 | * @param string $title |
||
| 54 | * @param string $description |
||
| 55 | * @param string $privacy |
||
| 56 | * @param string $layout |
||
| 57 | * @param string $cover |
||
| 58 | * @return AlbumInterface |
||
| 59 | */ |
||
| 60 | public function create( |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Update album |
||
| 107 | * |
||
| 108 | * @param string $id Imgur Id of the album |
||
| 109 | * @param array $ids Ids of the images you want to add to the album |
||
| 110 | * @param string $title |
||
| 111 | * @param string $description |
||
| 112 | * @param string $privacy |
||
| 113 | * @param string $layout |
||
| 114 | * @param string $cover |
||
| 115 | * @return bool |
||
| 116 | */ |
||
| 117 | public function update( |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Delete an album |
||
| 158 | * |
||
| 159 | * @param string $id Imgur Id or deletehash of the album |
||
| 160 | * @return bool |
||
| 161 | */ |
||
| 162 | public function delete($id) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Favorite an album |
||
| 173 | * |
||
| 174 | * @param string $id |
||
| 175 | * @return bool |
||
| 176 | */ |
||
| 177 | public function favorite($id) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Sets the images for an album, removes all other images and only uses the images in this request. |
||
| 188 | * |
||
| 189 | * @param string $id |
||
| 190 | * @param array $ids |
||
| 191 | * @return bool |
||
| 192 | */ |
||
| 193 | View Code Duplication | public function setImages($id, array $ids) |
|
| 209 | |||
| 210 | /** |
||
| 211 | * Adds images to an album |
||
| 212 | * |
||
| 213 | * @param string $id |
||
| 214 | * @param array $ids |
||
| 215 | * @return bool |
||
| 216 | */ |
||
| 217 | View Code Duplication | public function addImages($id, array $ids) |
|
| 233 | |||
| 234 | /** |
||
| 235 | * Removes images from an album |
||
| 236 | * |
||
| 237 | * @param string $id |
||
| 238 | * @param array $ids |
||
| 239 | * @return bool |
||
| 240 | */ |
||
| 241 | View Code Duplication | public function removeImages($id, array $ids) |
|
| 257 | } |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: