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 |
||
10 | class Storage |
||
11 | { |
||
12 | /** |
||
13 | * Prepare all the folders and files for storage. |
||
14 | */ |
||
15 | public static function prepare() |
||
43 | |||
44 | /** |
||
45 | * Prepare the folders for storage. |
||
46 | */ |
||
47 | public static function prepareFolders(array $paths = array(), $removeIfExists = false) |
||
67 | |||
68 | /** |
||
69 | * Prepare the uploads folder (so images can be uploaded). |
||
70 | */ |
||
71 | public static function prepareUploadsFolder($uploadsDirectory) |
||
96 | |||
97 | /** |
||
98 | * Prepare the log files. |
||
99 | */ |
||
100 | public static function prepareLogFiles(array $paths, $removeIfExists = false) |
||
116 | } |
||
117 |
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.