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 |
||
26 | View Code Duplication | class NonRootModuleExpectedException extends RuntimeException |
|
|
|||
27 | { |
||
28 | /** |
||
29 | * Creates an exception for a binding UUID that could not be enabled in the |
||
30 | * root module. |
||
31 | * |
||
32 | * @param Uuid $uuid The UUID. |
||
33 | * @param string $moduleName The name of the module. |
||
34 | * @param Exception|null $cause The exception that caused this |
||
35 | * exception. |
||
36 | * |
||
37 | * @return static The created exception. |
||
38 | */ |
||
39 | 1 | public static function cannotEnableBinding(Uuid $uuid, $moduleName, Exception $cause = null) |
|
48 | |||
49 | /** |
||
50 | * Creates an exception for a binding UUID that could not be disabled in the |
||
51 | * root module. |
||
52 | * |
||
53 | * @param Uuid $uuid The UUID. |
||
54 | * @param string $moduleName The name of the module. |
||
55 | * @param Exception|null $cause The exception that caused this |
||
56 | * exception. |
||
57 | * |
||
58 | * @return static The created exception. |
||
59 | */ |
||
60 | 1 | public static function cannotDisableBinding(Uuid $uuid, $moduleName, Exception $cause = null) |
|
69 | } |
||
70 |
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.