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) |
||
117 | |||
118 | /** |
||
119 | * Seed the specified module. |
||
120 | * |
||
121 | * @param string $className |
||
122 | */ |
||
123 | protected function dbSeed($className) |
||
139 | |||
140 | /** |
||
141 | * Get master database seeder name for the specified module. |
||
142 | * |
||
143 | * @param string $name |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | public function getSeederName($name) |
||
157 | |||
158 | /** |
||
159 | * Report the exception to the exception handler. |
||
160 | * |
||
161 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
162 | * @param \Throwable $e |
||
163 | * @return void |
||
164 | */ |
||
165 | protected function renderException($output, \Throwable $e) |
||
169 | |||
170 | /** |
||
171 | * Report the exception to the exception handler. |
||
172 | * |
||
173 | * @param \Throwable $e |
||
174 | * @return void |
||
175 | */ |
||
176 | protected function reportException(\Throwable $e) |
||
180 | |||
181 | /** |
||
182 | * Get the console command arguments. |
||
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | 92 | protected function getArguments() |
|
192 | |||
193 | /** |
||
194 | * Get the console command options. |
||
195 | * |
||
196 | * @return array |
||
197 | */ |
||
198 | 92 | View Code Duplication | protected function getOptions() |
206 | } |
||
207 |