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 |
||
| 26 | class PluginCommandHandler |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var RootPackageFileManager |
||
| 30 | */ |
||
| 31 | private $manager; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Creates the handler. |
||
| 35 | * |
||
| 36 | * @param RootPackageFileManager $manager The root package file manager. |
||
| 37 | */ |
||
| 38 | public function __construct(RootPackageFileManager $manager) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Handles the "puli plugin --list" command. |
||
| 45 | * |
||
| 46 | * @param Args $args The console arguments. |
||
| 47 | * @param IO $io The I/O. |
||
| 48 | * |
||
| 49 | * @return int The status code. |
||
| 50 | */ |
||
| 51 | public function handleList(Args $args, IO $io) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Handles the "puli plugin --install" command. |
||
| 70 | * |
||
| 71 | * @param Args $args The console arguments. |
||
| 72 | * |
||
| 73 | * @return int The status code. |
||
| 74 | */ |
||
| 75 | View Code Duplication | public function handleInstall(Args $args) |
|
| 90 | |||
| 91 | /** |
||
| 92 | * Handles the "puli plugin --remove" command. |
||
| 93 | * |
||
| 94 | * @param Args $args The console arguments. |
||
| 95 | * |
||
| 96 | * @return int The status code. |
||
| 97 | */ |
||
| 98 | View Code Duplication | public function handleDelete(Args $args) |
|
| 113 | } |
||
| 114 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.