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 |
||
6 | class GlobalConfiguration |
||
7 | { |
||
8 | /** |
||
9 | * Creates the configuration file. |
||
10 | * |
||
11 | * @param OutputInterface $output |
||
12 | */ |
||
13 | public static function create(OutputInterface $output) |
||
31 | |||
32 | /** |
||
33 | * Get the configuration. |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | View Code Duplication | public static function get() |
|
47 | |||
48 | /** |
||
49 | * Configuration skeleton |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | protected static function configSkeleton() |
||
59 | |||
60 | /** |
||
61 | * Checks if the configuration exists. |
||
62 | * |
||
63 | * @return boolean |
||
64 | */ |
||
65 | public static function exists() |
||
69 | |||
70 | /** |
||
71 | * Retrieves the configuration file. |
||
72 | * |
||
73 | * @return string The path to the configuration file. |
||
74 | */ |
||
75 | protected static function getConfigFile() |
||
79 | } |
||
80 |
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.