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 |
||
| 8 | class InstallCommand extends Command |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * The console command name. |
||
| 12 | * |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected $name = 'admin:install'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The console command description. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $description = 'Install the admin package'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $directory = ''; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Execute the console command. |
||
| 31 | * |
||
| 32 | * @return void |
||
| 33 | */ |
||
| 34 | public function fire() |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Create tables and seed it. |
||
| 43 | * |
||
| 44 | * @return void |
||
| 45 | */ |
||
| 46 | public function publishDatabase() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Initialize the admin directory. |
||
| 55 | * |
||
| 56 | * @return void |
||
| 57 | */ |
||
| 58 | protected function initAdminDirectory() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Create HomeController. |
||
| 86 | * |
||
| 87 | * @return void |
||
| 88 | */ |
||
| 89 | View Code Duplication | public function createHomeController() |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Create HomeController. |
||
| 103 | * |
||
| 104 | * @return void |
||
| 105 | */ |
||
| 106 | View Code Duplication | public function createExampleController() |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Create AuthController. |
||
| 120 | * |
||
| 121 | * @return void |
||
| 122 | */ |
||
| 123 | View Code Duplication | public function createAuthController() |
|
| 134 | |||
| 135 | /** |
||
| 136 | * Create AdministratorController. |
||
| 137 | * |
||
| 138 | * @return void |
||
| 139 | */ |
||
| 140 | View Code Duplication | public function createAdministratorController() |
|
| 153 | |||
| 154 | /** |
||
| 155 | * Create menu file. |
||
| 156 | * |
||
| 157 | * @return void |
||
| 158 | */ |
||
| 159 | protected function createMenuFile() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Create routes file. |
||
| 170 | * |
||
| 171 | * @return void |
||
| 172 | */ |
||
| 173 | protected function createRoutesFile() |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Copy language files to admin directory. |
||
| 184 | * |
||
| 185 | * @return void |
||
| 186 | */ |
||
| 187 | protected function copyLanguageFiles() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Get stub contents. |
||
| 194 | * |
||
| 195 | * @param $name |
||
| 196 | * |
||
| 197 | * @return string |
||
| 198 | */ |
||
| 199 | protected function getStub($name) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Make new directory. |
||
| 206 | * |
||
| 207 | * @param string $path |
||
| 208 | */ |
||
| 209 | protected function makeDir($path = '') |
||
| 213 | } |
||
| 214 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.