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 |
||
17 | class SeedCommand extends Command |
||
18 | { |
||
19 | use ModuleCommandTrait; |
||
20 | |||
21 | /** |
||
22 | * The console command name. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $name = 'module:seed'; |
||
27 | |||
28 | /** |
||
29 | * The console command description. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $description = 'Run database seeder from the specified module or from all modules.'; |
||
34 | |||
35 | /** |
||
36 | * Execute the console command. |
||
37 | * @throws FatalThrowableError |
||
38 | */ |
||
39 | public function handle() |
||
63 | |||
64 | /** |
||
65 | * @throws RuntimeException |
||
66 | * @return RepositoryInterface |
||
67 | */ |
||
68 | public function getModuleRepository(): RepositoryInterface |
||
77 | |||
78 | /** |
||
79 | * @param $name |
||
80 | * |
||
81 | * @throws RuntimeException |
||
82 | * |
||
83 | * @return Module |
||
84 | */ |
||
85 | public function getModuleByName($name) |
||
94 | |||
95 | /** |
||
96 | * @param Module $module |
||
97 | * |
||
98 | * @return void |
||
99 | */ |
||
100 | public function moduleSeed(Module $module) |
||
131 | |||
132 | /** |
||
133 | * Seed the specified module. |
||
134 | * |
||
135 | * @param string $className |
||
136 | */ |
||
137 | protected function dbSeed($className) |
||
155 | |||
156 | /** |
||
157 | * Get master database seeder name for the specified module. |
||
158 | * |
||
159 | * @param string $name |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getSeederName($name) |
||
173 | |||
174 | /** |
||
175 | * Get master database seeder name for the specified module under a different namespace than Modules. |
||
176 | * |
||
177 | * @param string $name |
||
178 | * |
||
179 | * @return array $foundModules array containing namespace paths |
||
180 | */ |
||
181 | public function getSeederNames($name) |
||
196 | |||
197 | /** |
||
198 | * Report the exception to the exception handler. |
||
199 | * |
||
200 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
201 | * @param \Throwable $e |
||
202 | * @return void |
||
203 | */ |
||
204 | protected function renderException($output, \Exception $e) |
||
208 | |||
209 | /** |
||
210 | * Report the exception to the exception handler. |
||
211 | * |
||
212 | * @param \Throwable $e |
||
213 | * @return void |
||
214 | */ |
||
215 | protected function reportException(\Exception $e) |
||
219 | |||
220 | /** |
||
221 | * Get the console command arguments. |
||
222 | * |
||
223 | * @return array |
||
224 | */ |
||
225 | 121 | protected function getArguments() |
|
231 | |||
232 | /** |
||
233 | * Get the console command options. |
||
234 | * |
||
235 | * @return array |
||
236 | */ |
||
237 | 121 | View Code Duplication | protected function getOptions() |
245 | } |
||
246 |