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 RouteServiceProvider extends ServiceProvider |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * This namespace is applied to your controller routes. |
||
| 14 | * |
||
| 15 | * In addition, it is set as the URL generator's root namespace. |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $namespace = 'App\Http\Controllers'; |
||
| 20 | /** |
||
| 21 | * Define your route model bindings, pattern filters, etc. |
||
| 22 | * |
||
| 23 | * @param \Illuminate\Routing\Router $router |
||
| 24 | * @return void |
||
| 25 | */ |
||
| 26 | public function boot(Router $router) |
||
| 31 | /** |
||
| 32 | * Define the routes for the application. |
||
| 33 | * |
||
| 34 | * @param \Illuminate\Routing\Router $router |
||
| 35 | * @return void |
||
| 36 | */ |
||
| 37 | public function map(Router $router) |
||
| 42 | /** |
||
| 43 | * Define the "web" routes for the application. |
||
| 44 | * |
||
| 45 | * These routes all receive session state, CSRF protection, etc. |
||
| 46 | * |
||
| 47 | * @param \Illuminate\Routing\Router $router |
||
| 48 | * @return void |
||
| 49 | */ |
||
| 50 | View Code Duplication | protected function mapWebRoutes(Router $router) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * @param Router $router |
||
| 61 | */ |
||
| 62 | View Code Duplication | protected function mapApiRoutes(Router $router) |
|
| 70 | } |
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.