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 RouteServiceProvider extends ServiceProvider |
||
20 | { |
||
21 | /** |
||
22 | * This namespace is applied to your controller routes. |
||
23 | * In addition, it is set as the URL generator's root namespace. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $namespace = 'App\Http\Controllers'; |
||
28 | |||
29 | /** |
||
30 | * Define your route model bindings, pattern filters, etc. |
||
31 | */ |
||
32 | public function boot(): void |
||
38 | |||
39 | /** |
||
40 | * @param Router $router |
||
41 | */ |
||
42 | public function map(Router $router): void |
||
48 | |||
49 | /** |
||
50 | * @param Router $router |
||
51 | */ |
||
52 | View Code Duplication | protected function mapApiRoutes(Router $router): void |
|
61 | |||
62 | /** |
||
63 | * @param Router $router |
||
64 | */ |
||
65 | View Code Duplication | protected function mapWebRoutes(Router $router): void |
|
74 | } |
||
75 |
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.