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 namespace Distilleries\Messenger; |
||
9 | class MessengerLumenServiceProvider extends ServiceProvider { |
||
10 | |||
11 | |||
12 | protected $package = 'messenger'; |
||
13 | protected $namespace = 'Distilleries\Messenger\Http\Controllers'; |
||
14 | |||
15 | |||
16 | public function boot() |
||
22 | |||
23 | /** |
||
24 | * Register the service provider. |
||
25 | * |
||
26 | * @return void |
||
27 | */ |
||
28 | View Code Duplication | public function register() |
|
43 | |||
44 | /** |
||
45 | * Get the services provided by the provider. |
||
46 | * |
||
47 | * @return string[] |
||
48 | */ |
||
49 | public function provides() |
||
53 | |||
54 | |||
55 | public function alias() { |
||
61 | |||
62 | /** |
||
63 | * Define the routes for the application. |
||
64 | * |
||
65 | * @param \Illuminate\Routing\Router $router |
||
66 | * @return void |
||
67 | */ |
||
68 | public function map() |
||
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.