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 |
||
7 | View Code Duplication | class RouteServiceProvider extends ServiceProvider |
|
|
|||
8 | { |
||
9 | /** |
||
10 | * This namespace is applied to the controller routes in your module's routes file. |
||
11 | * |
||
12 | * In addition, it is set as the URL generator's root namespace. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $namespace = 'App\Modules\Reporting\Http\Controllers'; |
||
17 | |||
18 | /** |
||
19 | * Define your module's route model bindings, pattern filters, etc. |
||
20 | * |
||
21 | * @param \Illuminate\Routing\Router $router |
||
22 | * @return void |
||
23 | */ |
||
24 | public function boot(Router $router) |
||
30 | |||
31 | /** |
||
32 | * Define the routes for the module. |
||
33 | * |
||
34 | * @param \Illuminate\Routing\Router $router |
||
35 | * @return void |
||
36 | */ |
||
37 | public function map(Router $router) |
||
44 | } |
||
45 |
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.