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 |
||
9 | class ScaffoldMakeCommand extends Command |
||
10 | { |
||
11 | /** |
||
12 | * The console command name. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $name = 'generate:scaffold'; |
||
17 | |||
18 | /** |
||
19 | * The console command description. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $description = 'Create a new scaffold'; |
||
24 | |||
25 | /** |
||
26 | * Execute the console command. |
||
27 | * |
||
28 | * @return bool|null |
||
29 | */ |
||
30 | public function handle() |
||
31 | { |
||
32 | $name = $this->argument('name'); |
||
33 | |||
34 | $this->call('generate:controller', ['name' => $name]); |
||
35 | $this->call('generate:view', ['name' => $name, '--view' => 'index']); |
||
36 | $this->call('generate:view', ['name' => $name, '--view' => 'create']); |
||
37 | $this->call('generate:view', ['name' => $name, '--view' => 'edit']); |
||
38 | $this->call('generate:view', ['name' => $name, '--view' => '_form']); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Get the console command arguments. |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | protected function getArguments() |
||
52 | |||
53 | /** |
||
54 | * Get the console command options. |
||
55 | * |
||
56 | * @return array |
||
57 | */ |
||
58 | View Code Duplication | protected function getOptions() |
|
65 | } |
||
66 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.