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 |
||
14 | trait ProvidersLoaderTrait |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Loads only the Main Service Providers from the Containers. |
||
19 | * All the Service Providers (registered inside the main), will be |
||
20 | * loaded from the `boot()` function on the parent of the Main |
||
21 | * Service Providers. |
||
22 | * |
||
23 | * @param $containerName |
||
24 | */ |
||
25 | public function loadOnlyMainProvidersFromContainers($containerName) |
||
31 | |||
32 | /** |
||
33 | * @param $directory |
||
34 | */ |
||
35 | private function loadProviders($directory) |
||
58 | |||
59 | /** |
||
60 | * @param $providerFullName |
||
61 | */ |
||
62 | private function loadProvider($providerFullName) |
||
66 | |||
67 | /** |
||
68 | * @void |
||
69 | */ |
||
70 | public function loadServiceProviders() |
||
76 | |||
77 | } |
||
78 |
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.