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 |
||
| 23 | class Server extends AbstractApi |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @param int $per_page |
||
| 27 | * @param int $page |
||
| 28 | * @param string|null $tag |
||
| 29 | * |
||
| 30 | * @return DropletEntity[] |
||
| 31 | */ |
||
| 32 | public function list($per_page = 200, $page = 1, $tag = null) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param int $id |
||
| 51 | * |
||
| 52 | * @return DropletEntity[] |
||
| 53 | */ |
||
| 54 | public function getNeighborsById($id) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return DropletEntity[] |
||
| 67 | */ |
||
| 68 | public function getAllNeighbors() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return UpgradeEntity[] |
||
| 81 | */ |
||
| 82 | View Code Duplication | public function getUpgrades() |
|
| 92 | |||
| 93 | /** |
||
| 94 | * @param int $id |
||
| 95 | * |
||
| 96 | * @throws HttpException |
||
| 97 | * |
||
| 98 | * @return DropletEntity |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function getById($id) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * @param int $dcId |
||
| 111 | * @param string $vpsPlanId |
||
| 112 | * @param string $osId |
||
| 113 | * @param array $options |
||
| 114 | * |
||
| 115 | * @throws HttpException |
||
| 116 | * |
||
| 117 | * @return DropletEntity|null |
||
| 118 | */ |
||
| 119 | public function create($dcId, $vpsPlanId, $osId, array $options) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @param int $id |
||
| 165 | * |
||
| 166 | * @throws HttpException |
||
| 167 | */ |
||
| 168 | public function delete($id) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @param int $id |
||
| 175 | * |
||
| 176 | * @throws HttpException |
||
| 177 | * |
||
| 178 | * @return KernelEntity[] |
||
| 179 | */ |
||
| 180 | View Code Duplication | public function getAvailableKernels($id) |
|
| 192 | |||
| 193 | /** |
||
| 194 | * @param int $id |
||
| 195 | * |
||
| 196 | * @return ImageEntity[] |
||
| 197 | */ |
||
| 198 | View Code Duplication | public function getSnapshots($id) |
|
| 212 | |||
| 213 | /** |
||
| 214 | * @param int $id |
||
| 215 | * |
||
| 216 | * @return ImageEntity[] |
||
| 217 | */ |
||
| 218 | View Code Duplication | public function getBackups($id) |
|
| 230 | |||
| 231 | /** |
||
| 232 | * @param int $id |
||
| 233 | * |
||
| 234 | * @return ActionEntity[] |
||
| 235 | */ |
||
| 236 | View Code Duplication | public function getActions($id) |
|
| 248 | |||
| 249 | /** |
||
| 250 | * @param int $id |
||
| 251 | * @param int $actionId |
||
| 252 | * |
||
| 253 | * @return ActionEntity |
||
| 254 | */ |
||
| 255 | View Code Duplication | public function getActionById($id, $actionId) |
|
| 263 | |||
| 264 | /** |
||
| 265 | * @param int $id |
||
| 266 | * |
||
| 267 | * @throws HttpException |
||
| 268 | * |
||
| 269 | * @return ActionEntity |
||
| 270 | */ |
||
| 271 | public function reboot($id) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @param int $id |
||
| 278 | * |
||
| 279 | * @throws HttpException |
||
| 280 | * |
||
| 281 | * @return ActionEntity |
||
| 282 | */ |
||
| 283 | public function powerCycle($id) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param int $id |
||
| 290 | * |
||
| 291 | * @throws HttpException |
||
| 292 | * |
||
| 293 | * @return ActionEntity |
||
| 294 | */ |
||
| 295 | public function shutdown($id) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param int $id |
||
| 302 | * |
||
| 303 | * @throws HttpException |
||
| 304 | * |
||
| 305 | * @return ActionEntity |
||
| 306 | */ |
||
| 307 | public function powerOff($id) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @param int $id |
||
| 314 | * |
||
| 315 | * @throws HttpException |
||
| 316 | * |
||
| 317 | * @return ActionEntity |
||
| 318 | */ |
||
| 319 | public function powerOn($id) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @param int $id |
||
| 326 | * |
||
| 327 | * @throws HttpException |
||
| 328 | * |
||
| 329 | * @return ActionEntity |
||
| 330 | */ |
||
| 331 | public function passwordReset($id) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @param int $id |
||
| 338 | * @param string $size |
||
| 339 | * @param bool $disk |
||
| 340 | * |
||
| 341 | * @throws HttpException |
||
| 342 | * |
||
| 343 | * @return ActionEntity |
||
| 344 | */ |
||
| 345 | public function resize($id, $size, $disk = true) |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @param int $id |
||
| 352 | * @param int $image |
||
| 353 | * |
||
| 354 | * @throws HttpException |
||
| 355 | * |
||
| 356 | * @return ActionEntity |
||
| 357 | */ |
||
| 358 | public function restore($id, $image) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @param int $id |
||
| 365 | * @param int|string $image |
||
| 366 | * |
||
| 367 | * @throws HttpException |
||
| 368 | * |
||
| 369 | * @return ActionEntity |
||
| 370 | */ |
||
| 371 | public function rebuild($id, $image) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @param int $id |
||
| 378 | * @param string $name |
||
| 379 | * |
||
| 380 | * @throws HttpException |
||
| 381 | * |
||
| 382 | * @return ActionEntity |
||
| 383 | */ |
||
| 384 | public function rename($id, $name) |
||
| 388 | |||
| 389 | /** |
||
| 390 | * @param int $id |
||
| 391 | * @param int $kernel |
||
| 392 | * |
||
| 393 | * @throws HttpException |
||
| 394 | * |
||
| 395 | * @return ActionEntity |
||
| 396 | */ |
||
| 397 | public function changeKernel($id, $kernel) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @param int $id |
||
| 404 | * |
||
| 405 | * @throws HttpException |
||
| 406 | * |
||
| 407 | * @return ActionEntity |
||
| 408 | */ |
||
| 409 | public function enableIpv6($id) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * @param int $id |
||
| 416 | * |
||
| 417 | * @throws HttpException |
||
| 418 | * |
||
| 419 | * @return ActionEntity |
||
| 420 | */ |
||
| 421 | public function enableBackups($id) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @param int $id |
||
| 428 | * |
||
| 429 | * @throws HttpException |
||
| 430 | * |
||
| 431 | * @return ActionEntity |
||
| 432 | */ |
||
| 433 | public function disableBackups($id) |
||
| 437 | |||
| 438 | /** |
||
| 439 | * @param int $id |
||
| 440 | * |
||
| 441 | * @throws HttpException |
||
| 442 | * |
||
| 443 | * @return ActionEntity |
||
| 444 | */ |
||
| 445 | public function enablePrivateNetworking($id) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @param int $id |
||
| 452 | * @param string $name |
||
| 453 | * |
||
| 454 | * @throws HttpException |
||
| 455 | * |
||
| 456 | * @return ActionEntity |
||
| 457 | */ |
||
| 458 | public function snapshot($id, $name) |
||
| 462 | |||
| 463 | /** |
||
| 464 | * @param int $id |
||
| 465 | * @param array $options |
||
| 466 | * |
||
| 467 | * @throws HttpException |
||
| 468 | * |
||
| 469 | * @return ActionEntity |
||
| 470 | */ |
||
| 471 | View Code Duplication | private function executeAction($id, array $options) |
|
| 479 | } |
||
| 480 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.