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 |
||
8 | class Cray extends GeneratorCommand |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * The console command name. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $name = 'cray'; |
||
17 | /** |
||
18 | * The name and signature of the console command. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $signature = 'cray |
||
23 | {name : Model name. Controller, factory, migration, views will be based on this name.} |
||
24 | {--views-dir= : Place views in a sub-directory under the views directory. It can be any nested directory structure} |
||
25 | {--controller-dir= : Place controller in a sub-directory under the Http/Controllers directory. It can be any nested directory structure} |
||
26 | {--stubs-dir= : Specify a custom stubs directory} |
||
27 | {--no-views : Do not create view files for the model} |
||
28 | {--no-migration : Do not create a migration for the model} |
||
29 | {--no-factory : Do not create a factory for the model} |
||
30 | '; |
||
31 | |||
32 | /** |
||
33 | * The console command description. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $description = 'Scaffold a nearly complete boilerplate CRUD pages for the specified Model'; |
||
38 | |||
39 | /** |
||
40 | * Create a new command instance. |
||
41 | * |
||
42 | */ |
||
43 | /* public function __construct() |
||
44 | { |
||
45 | parent::__construct(); |
||
46 | }*/ |
||
47 | |||
48 | /** |
||
49 | * Execute the console command. |
||
50 | * |
||
51 | * @return mixed |
||
52 | */ |
||
53 | public function handle() |
||
88 | |||
89 | /** |
||
90 | * Create a model factory for the model. |
||
91 | * |
||
92 | * @return void |
||
93 | */ |
||
94 | View Code Duplication | protected function createFactory() |
|
103 | |||
104 | /** |
||
105 | * Create a migration file for the model. |
||
106 | * |
||
107 | * @return void |
||
108 | */ |
||
109 | View Code Duplication | protected function createMigration() |
|
118 | |||
119 | /** |
||
120 | * Create a controller for the model. |
||
121 | * |
||
122 | * @return void |
||
123 | */ |
||
124 | protected function createController() |
||
148 | |||
149 | protected function createViews() |
||
170 | |||
171 | /** |
||
172 | * Create a controller for the model. |
||
173 | * |
||
174 | * @param string $requestType |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | protected function createRequest($requestType = 'Store') |
||
188 | |||
189 | /** |
||
190 | * Get the stub file for the generator. |
||
191 | * |
||
192 | * @return string |
||
193 | */ |
||
194 | protected function getStub() |
||
198 | |||
199 | /** |
||
200 | * Get the default namespace for the class. |
||
201 | * |
||
202 | * @param string $rootNamespace |
||
203 | * |
||
204 | * @return string |
||
205 | */ |
||
206 | protected function getDefaultNamespace($rootNamespace) |
||
215 | } |
||
216 |
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.