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 |
||
| 16 | class EmojiController |
||
| 17 | { |
||
| 18 | public $authController; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * This is a constructor; a default method that will be called automatically during class instantiation. |
||
| 22 | */ |
||
| 23 | public function __construct() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Get all emojis. |
||
| 30 | * |
||
| 31 | * @param Slim\Http\Request $request |
||
| 32 | * @param Slim\Http\Response $response |
||
| 33 | * @param array $args |
||
| 34 | * |
||
| 35 | * @return Slim\Http\Response |
||
| 36 | */ |
||
| 37 | View Code Duplication | public function getAllEmojis($request, $response, $args) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * Get a single emoji. |
||
| 50 | * |
||
| 51 | * @param Slim\Http\Request $request |
||
| 52 | * @param Slim\Http\Response $response |
||
| 53 | * @param array $args |
||
| 54 | * |
||
| 55 | * @return Slim\Http\Response |
||
| 56 | */ |
||
| 57 | View Code Duplication | public function getSingleEmoji($request, $response, $args) |
|
| 67 | |||
| 68 | /** |
||
| 69 | * This method creates emoji and keywords associated with it. |
||
| 70 | * |
||
| 71 | * @param $request |
||
| 72 | * @param $response |
||
| 73 | * @param $requestParams |
||
| 74 | * |
||
| 75 | * @return json response |
||
| 76 | */ |
||
| 77 | public function CreateEmoji($request, $response, $requestParams) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * This method updates an emoji by using Patch. |
||
| 114 | * |
||
| 115 | * @param $request |
||
| 116 | * @param $response |
||
| 117 | * @param $args |
||
| 118 | * |
||
| 119 | * @return json $response |
||
| 120 | */ |
||
| 121 | public function updateEmojiByPatch($request, $response, $args) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * This method updates an emoji by using put. |
||
| 145 | * |
||
| 146 | * @param $request |
||
| 147 | * @param $response |
||
| 148 | * @param $args |
||
| 149 | * |
||
| 150 | * @return json $response |
||
| 151 | */ |
||
| 152 | public function updateEmojiByPut($request, $response, $args) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * This method deletes an emoji. |
||
| 176 | * |
||
| 177 | * @param Slim\Http\Request $request |
||
| 178 | * @param Slim\Http\Response $response |
||
| 179 | * @param array $args |
||
| 180 | * |
||
| 181 | * @return json response |
||
| 182 | */ |
||
| 183 | public function deleteEmoji($request, $response, $args) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * This method authenticate and returns user id. |
||
| 198 | * |
||
| 199 | * @param $response |
||
| 200 | * @param $request |
||
| 201 | * |
||
| 202 | * @return user id |
||
| 203 | */ |
||
| 204 | public function getUserId($request, $response) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * This method solves for rightful owner of a record. |
||
| 225 | * |
||
| 226 | * @param $response |
||
| 227 | * @param $request |
||
| 228 | * @param $args |
||
| 229 | * |
||
| 230 | * @return user id |
||
| 231 | */ |
||
| 232 | public function getTheOwner($request, $response, $args) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * This method creates emoji keywords. |
||
| 241 | * |
||
| 242 | * @param $emoji_id |
||
| 243 | * @param $keywords |
||
| 244 | * |
||
| 245 | * @return keyword id |
||
| 246 | */ |
||
| 247 | public function createEmojiKeywords($emoji_id, $keywords) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * This method checks for empty input from user. |
||
| 271 | * |
||
| 272 | * @param $inputName |
||
| 273 | * @param $inputChars |
||
| 274 | * @param $inputCategory |
||
| 275 | * @param $inputKeywords |
||
| 276 | * |
||
| 277 | * @return bool |
||
| 278 | */ |
||
| 279 | public function checkEmptyInput($inputName, $inputChars, $inputCategory, $inputKeywords) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * This method checks for duplicate emoji. |
||
| 290 | * |
||
| 291 | * @param $inputName |
||
| 292 | * @param $inputChars |
||
| 293 | * |
||
| 294 | * @return bool |
||
| 295 | */ |
||
| 296 | public function checkDuplicateEmoji($inputName, $inputChars) |
||
| 308 | |||
| 309 | /** |
||
| 310 | * This method checks for empty input from user. |
||
| 311 | * |
||
| 312 | * @param $request |
||
| 313 | * @param $response |
||
| 314 | * @param $args |
||
| 315 | * |
||
| 316 | * @return bool |
||
| 317 | */ |
||
| 318 | public function validateArgs($request, $response, $args) |
||
| 332 | } |
||
| 333 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.