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 |
||
| 8 | class RouteServiceProvider extends ServiceProvider |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * This namespace is applied to your controller routes. |
||
| 12 | * |
||
| 13 | * In addition, it is set as the URL generator's root namespace. |
||
| 14 | * |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | protected $namespace = 'App\Http\Controllers'; |
||
| 18 | /** |
||
| 19 | * Define your route model bindings, pattern filters, etc. |
||
| 20 | * |
||
| 21 | * @param \Illuminate\Routing\Router $router |
||
| 22 | * @return void |
||
| 23 | */ |
||
| 24 | public function boot(Router $router) |
||
| 29 | /** |
||
| 30 | * Define the routes for the application. |
||
| 31 | * |
||
| 32 | * @param \Illuminate\Routing\Router $router |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | public function map(Router $router) |
||
| 43 | /** |
||
| 44 | * Define the "web" routes for the application. |
||
| 45 | * |
||
| 46 | * These routes all receive session state, CSRF protection, etc. |
||
| 47 | * |
||
| 48 | * @param \Illuminate\Routing\Router $router |
||
| 49 | * @return void |
||
| 50 | */ |
||
| 51 | protected function mapNoMiddlewareRoutes(Router $router) |
||
| 59 | /** |
||
| 60 | * Define the "web" routes for the application. |
||
| 61 | * |
||
| 62 | * These routes all receive session state, CSRF protection, etc. |
||
| 63 | * |
||
| 64 | * @param \Illuminate\Routing\Router $router |
||
| 65 | * @return void |
||
| 66 | */ |
||
| 67 | View Code Duplication | protected function mapWebRoutes(Router $router) |
|
| 75 | /** |
||
| 76 | * Define the "web" routes for the application. |
||
| 77 | * |
||
| 78 | * These routes all receive session state, CSRF protection, etc. |
||
| 79 | * |
||
| 80 | * @param \Illuminate\Routing\Router $router |
||
| 81 | * @return void |
||
| 82 | */ |
||
| 83 | View Code Duplication | protected function mapApiRoutes(Router $router) |
|
| 91 | } |
||
| 92 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.