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 ApcalUtility extends XoopsObject |
||
7 | { |
||
8 | /** |
||
9 | * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
||
10 | * |
||
11 | * @param string $folder The full path of the directory to check |
||
12 | * |
||
13 | * @return void |
||
14 | */ |
||
15 | public static function createFolder($folder) |
||
39 | |||
40 | /** |
||
41 | * @param $file |
||
42 | * @param $folder |
||
43 | * @return bool |
||
44 | */ |
||
45 | public static function copyFile($file, $folder) |
||
59 | |||
60 | /** |
||
61 | * @param $src |
||
62 | * @param $dst |
||
63 | */ |
||
64 | public static function recurseCopy($src, $dst) |
||
79 | |||
80 | /** |
||
81 | * |
||
82 | * Verifies XOOPS version meets minimum requirements for this module |
||
83 | * @static |
||
84 | * @param XoopsModule $module |
||
85 | * |
||
86 | * @return bool true if meets requirements, false if not |
||
87 | */ |
||
88 | View Code Duplication | public static function checkVerXoops(XoopsModule $module) |
|
103 | |||
104 | /** |
||
105 | * |
||
106 | * Verifies PHP version meets minimum requirements for this module |
||
107 | * @static |
||
108 | * @param XoopsModule $module |
||
109 | * |
||
110 | * @return bool true if meets requirements, false if not |
||
111 | */ |
||
112 | View Code Duplication | public static function checkVerPhp(XoopsModule $module) |
|
128 | } |
||
129 |
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.