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 SetupCommand extends Command |
||
17 | { |
||
18 | use DetectsApplicationNamespace; |
||
19 | |||
20 | /** |
||
21 | * The name and signature of the console command. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $signature = 'canvas:setup {--data : Specifies that demo data should be seeded}'; |
||
26 | |||
27 | /** |
||
28 | * The console command description. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $description = 'Scaffold basic blog views and routes'; |
||
33 | |||
34 | /** |
||
35 | * The views that need to be exported. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $views = [ |
||
40 | 'layouts/app.stub' => 'layouts/app.blade.php', |
||
41 | 'partials/navbar.stub' => 'partials/navbar.blade.php', |
||
42 | 'partials/styles.stub' => 'partials/styles.blade.php', |
||
43 | 'index.stub' => 'index.blade.php', |
||
44 | 'show.stub' => 'show.blade.php', |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * Execute the console command. |
||
49 | * |
||
50 | * @return void |
||
51 | * @throws \Exception |
||
52 | */ |
||
53 | public function handle() |
||
71 | |||
72 | /** |
||
73 | * Create the view directories. |
||
74 | * |
||
75 | * @return void |
||
76 | */ |
||
77 | private function createDirectories() |
||
87 | |||
88 | /** |
||
89 | * Export the default blog views. |
||
90 | * |
||
91 | * @return void |
||
92 | */ |
||
93 | private function exportViews() |
||
108 | |||
109 | /** |
||
110 | * Build the new controller. |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | private function buildController() |
||
124 | |||
125 | /** |
||
126 | * Export the new controller. |
||
127 | * |
||
128 | * @return void |
||
129 | */ |
||
130 | private function exportController() |
||
137 | |||
138 | /** |
||
139 | * Compile the default controller stub. |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | private function compileControllerStub() |
||
151 | |||
152 | /** |
||
153 | * Register the new routes. |
||
154 | * |
||
155 | * @return void |
||
156 | */ |
||
157 | private function registerRoutes() |
||
167 | |||
168 | /** |
||
169 | * Run the demo data seeder. |
||
170 | * |
||
171 | * @return void |
||
172 | * @throws \Exception |
||
173 | */ |
||
174 | private function seed() |
||
242 | } |
||
243 |
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.