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 |
||
10 | class ModelMakeCommand extends GeneratorCommand |
||
11 | { |
||
12 | /** |
||
13 | * The console command name. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $name = 'cray:model'; |
||
18 | |||
19 | /** |
||
20 | * The console command description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Create a new Eloquent model class'; |
||
25 | |||
26 | /** |
||
27 | * The type of class being generated. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $type = 'Model'; |
||
32 | |||
33 | /** |
||
34 | * Execute the console command. |
||
35 | * |
||
36 | * @return void |
||
37 | */ |
||
38 | public function handle() |
||
62 | |||
63 | /** |
||
64 | * Create a model factory for the model. |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | View Code Duplication | protected function createFactory() |
|
77 | |||
78 | /** |
||
79 | * Create a migration file for the model. |
||
80 | * |
||
81 | * @return void |
||
82 | */ |
||
83 | View Code Duplication | protected function createMigration() |
|
92 | |||
93 | /** |
||
94 | * Create a controller for the model. |
||
95 | * |
||
96 | * @return void |
||
97 | */ |
||
98 | protected function createController() |
||
109 | |||
110 | /** |
||
111 | * Get the stub file for the generator. |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | protected function getStub() |
||
123 | |||
124 | /** |
||
125 | * Get the default namespace for the class. |
||
126 | * |
||
127 | * @param string $rootNamespace |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | protected function getDefaultNamespace($rootNamespace) |
||
135 | |||
136 | /** |
||
137 | * Get the console command options. |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | protected function getOptions() |
||
174 | } |
||
175 |
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.