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 |
||
| 19 | class ExportCommand extends Command |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * The name and signature of the console command. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $signature = 'multilang:export |
||
| 27 | {--path=storage/multilang : The path to multilang folder} |
||
| 28 | {--lang= : Comma separated langs to export, default all} |
||
| 29 | {--scope= : Comma separated scopes, default all} |
||
| 30 | {--force : Force update existing texts in files} |
||
| 31 | {--clear : Clear texts from files before export} |
||
| 32 | '; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * The console command description. |
||
| 36 | * |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $description = 'Export texts from database to yml files.'; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The name of texts table. |
||
| 43 | * |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | protected $table; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The database connection instance. |
||
| 50 | * |
||
| 51 | * @var \Illuminate\Database\Connection |
||
| 52 | */ |
||
| 53 | protected $db; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * The path to texts files. |
||
| 57 | * |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | protected $path; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * The langs. |
||
| 64 | * |
||
| 65 | * @var array |
||
| 66 | */ |
||
| 67 | protected $langs; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * The available scopes. |
||
| 71 | * |
||
| 72 | * @var array |
||
| 73 | */ |
||
| 74 | protected $scopes = ['global', 'site', 'admin']; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Execute the console command. |
||
| 78 | * |
||
| 79 | * @return mixed |
||
| 80 | */ |
||
| 81 | public function handle() |
||
| 145 | |||
| 146 | protected function export($scope = 'global', $force = false, $clear = false) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Get a texts from file. |
||
| 170 | * |
||
| 171 | * @return array |
||
| 172 | */ |
||
| 173 | protected function getTextsFromFile($scope) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Get a texts from database. |
||
| 191 | * |
||
| 192 | * @return array |
||
| 193 | */ |
||
| 194 | protected function getTextsFromDb($scope) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Get a database connection instance. |
||
| 215 | * |
||
| 216 | * @return \Illuminate\Database\Connection |
||
| 217 | */ |
||
| 218 | View Code Duplication | protected function getDatabase() |
|
| 227 | } |
||
| 228 |
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.