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 SeedCommand extends Command |
||
| 17 | { |
||
| 18 | use ModuleCommandTrait; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * The console command name. |
||
| 22 | * |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $name = 'module:seed'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * The console command description. |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $description = 'Run database seeder from the specified module or from all modules.'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Execute the console command. |
||
| 36 | * @throws FatalThrowableError |
||
| 37 | */ |
||
| 38 | public function handle() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @throws RuntimeException |
||
| 60 | * @return RepositoryInterface |
||
| 61 | */ |
||
| 62 | public function getModuleRepository(): RepositoryInterface |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param $name |
||
| 74 | * |
||
| 75 | * @throws RuntimeException |
||
| 76 | * |
||
| 77 | * @return Module |
||
| 78 | */ |
||
| 79 | public function getModuleByName($name) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param Module $module |
||
| 91 | * |
||
| 92 | * @return void |
||
| 93 | */ |
||
| 94 | public function moduleSeed(Module $module) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Seed the specified module. |
||
| 128 | * |
||
| 129 | * @param string $className |
||
| 130 | */ |
||
| 131 | protected function dbSeed($className) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Get master database seeder name for the specified module. |
||
| 152 | * |
||
| 153 | * @param string $name |
||
| 154 | * |
||
| 155 | * @return string |
||
| 156 | */ |
||
| 157 | public function getSeederName($name) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Get master database seeder name for the specified module under a different namespace than Modules. |
||
| 170 | * |
||
| 171 | * @param string $name |
||
| 172 | * |
||
| 173 | * @return array $foundModules array containing namespace paths |
||
| 174 | */ |
||
| 175 | public function getSeederNames($name) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Report the exception to the exception handler. |
||
| 193 | * |
||
| 194 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
| 195 | * @param \Throwable $e |
||
| 196 | * @return void |
||
| 197 | */ |
||
| 198 | protected function renderException($output, \Throwable $e) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Report the exception to the exception handler. |
||
| 205 | * |
||
| 206 | * @param \Throwable $e |
||
| 207 | * @return void |
||
| 208 | */ |
||
| 209 | protected function reportException(\Throwable $e) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Get the console command arguments. |
||
| 216 | * |
||
| 217 | * @return array |
||
| 218 | */ |
||
| 219 | 95 | protected function getArguments() |
|
| 225 | |||
| 226 | /** |
||
| 227 | * Get the console command options. |
||
| 228 | * |
||
| 229 | * @return array |
||
| 230 | */ |
||
| 231 | 95 | View Code Duplication | protected function getOptions() |
| 239 | } |
||
| 240 |