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 RouteTranslationsListCommand extends RouteListCommand |
||
| 11 | { |
||
| 12 | use TranslatedRouteCommandContext; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | protected $name = 'route:trans:list'; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $description = 'List all registered routes for specific locales'; |
||
| 23 | |||
| 24 | |||
| 25 | /** |
||
| 26 | * Execute the console command. |
||
| 27 | */ |
||
| 28 | View Code Duplication | public function handle() |
|
| 46 | |||
| 47 | /** |
||
| 48 | * Boot a fresh copy of the application and get the routes. |
||
| 49 | * |
||
| 50 | * @param string $locale |
||
| 51 | * @return \Illuminate\Routing\RouteCollection |
||
| 52 | */ |
||
| 53 | protected function getFreshApplicationRoutes($locale) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Get the console command arguments. |
||
| 70 | * |
||
| 71 | * @return array |
||
| 72 | */ |
||
| 73 | protected function getArguments() |
||
| 79 | } |
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.