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 |
||
20 | class ImportCommand extends Command |
||
21 | { |
||
22 | /** |
||
23 | * The name and signature of the console command. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $signature = 'multilang:import |
||
28 | {--path=storage/multilang : The path to multilang folder} |
||
29 | {--lang= : Comma separated langs to import, default all} |
||
30 | {--scope= : Comma separated scopes, default all} |
||
31 | {--force : Force update existing texts in database}'; |
||
32 | |||
33 | /** |
||
34 | * The console command description. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $description = 'Import texts in database from yml files.'; |
||
39 | |||
40 | /** |
||
41 | * The name of texts table. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $table; |
||
46 | |||
47 | /** |
||
48 | * The database connection instance. |
||
49 | * |
||
50 | * @var \Illuminate\Database\Connection |
||
51 | */ |
||
52 | protected $db; |
||
53 | |||
54 | /** |
||
55 | * The path to texts files. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $path; |
||
60 | |||
61 | /** |
||
62 | * The langs. |
||
63 | * |
||
64 | * @var array |
||
65 | */ |
||
66 | protected $langs; |
||
67 | |||
68 | /** |
||
69 | * The available scopes. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $scopes = ['global', 'site', 'admin']; |
||
74 | |||
75 | /** |
||
76 | * Execute the console command. |
||
77 | * |
||
78 | * @return mixed |
||
79 | */ |
||
80 | public function handle() |
||
112 | |||
113 | protected function import($scope = 'global', $force = false) |
||
180 | |||
181 | /** |
||
182 | * Get a database connection instance. |
||
183 | * |
||
184 | * @return \Illuminate\Database\Connection |
||
185 | */ |
||
186 | View Code Duplication | protected function getDatabase() |
|
195 | } |
||
196 |
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.