| Conditions | 8 |
| Paths | 50 |
| Total Lines | 196 |
| Code Lines | 165 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 37 | public static function function_qualifier($src_path, $dst_path, $moduleName) { |
||
| 38 | |||
| 39 | $functions = []; |
||
| 40 | $constants = []; |
||
| 41 | |||
| 42 | //php functions |
||
| 43 | $functions[] = [ |
||
| 44 | 'array_diff', |
||
| 45 | 'array_filter', |
||
| 46 | 'array_key_exists', |
||
| 47 | 'array_keys', |
||
| 48 | 'array_search', |
||
| 49 | 'array_slice', |
||
| 50 | 'array_unshift', |
||
| 51 | 'array_values', |
||
| 52 | 'array_flip', |
||
| 53 | 'assert', |
||
| 54 | 'basename', |
||
| 55 | 'boolval', |
||
| 56 | 'call_user_func', |
||
| 57 | 'call_user_func_array', |
||
| 58 | 'chr', |
||
| 59 | 'class_exists', |
||
| 60 | 'closedir', |
||
| 61 | 'constant', |
||
| 62 | 'copy', |
||
| 63 | 'count', |
||
| 64 | 'curl_close', |
||
| 65 | 'curl_error', |
||
| 66 | 'curl_exec', |
||
| 67 | 'curl_file_create', |
||
| 68 | 'curl_getinfo', |
||
| 69 | 'curl_init', |
||
| 70 | 'curl_setopt', |
||
| 71 | 'define', |
||
| 72 | 'defined', |
||
| 73 | 'dirname', |
||
| 74 | 'doubleval', |
||
| 75 | 'explode', |
||
| 76 | 'extension_loaded', |
||
| 77 | 'file_exists', |
||
| 78 | 'finfo_open', |
||
| 79 | 'floatval', |
||
| 80 | 'floor', |
||
| 81 | 'formatTimestamp', |
||
| 82 | 'func_get_args', |
||
| 83 | 'func_num_args', |
||
| 84 | 'function_exists', |
||
| 85 | 'get_called_class', |
||
| 86 | 'get_class', |
||
| 87 | 'getimagesize', |
||
| 88 | 'gettype', |
||
| 89 | 'imagecopyresampled', |
||
| 90 | 'imagecreatefromgif', |
||
| 91 | 'imagecreatefromjpeg', |
||
| 92 | 'imagecreatefrompng', |
||
| 93 | 'imagecreatefromstring', |
||
| 94 | 'imagecreatetruecolor', |
||
| 95 | 'imagedestroy', |
||
| 96 | 'imagegif', |
||
| 97 | 'imagejpeg', |
||
| 98 | 'imagepng', |
||
| 99 | 'imagerotate', |
||
| 100 | 'imagesx', |
||
| 101 | 'imagesy', |
||
| 102 | 'implode', |
||
| 103 | 'in_array', |
||
| 104 | 'ini_get', |
||
| 105 | 'intval', |
||
| 106 | 'is_array', |
||
| 107 | 'is_bool', |
||
| 108 | 'is_callable', |
||
| 109 | 'is_dir', |
||
| 110 | 'is_double', |
||
| 111 | 'is_float', |
||
| 112 | 'is_int', |
||
| 113 | 'is_integer', |
||
| 114 | 'is_link', |
||
| 115 | 'is_long', |
||
| 116 | 'is_null', |
||
| 117 | 'is_object', |
||
| 118 | 'is_real', |
||
| 119 | 'is_resource', |
||
| 120 | 'is_string', |
||
| 121 | 'json_decode', |
||
| 122 | 'json_encode', |
||
| 123 | 'mime_content_type', |
||
| 124 | 'mkdir', |
||
| 125 | 'opendir', |
||
| 126 | 'ord', |
||
| 127 | 'pathinfo', |
||
| 128 | 'preg_match', |
||
| 129 | 'preg_match_all', |
||
| 130 | 'preg_replace', |
||
| 131 | 'readdir', |
||
| 132 | 'readlink', |
||
| 133 | 'redirect_header', |
||
| 134 | 'rename', |
||
| 135 | 'rmdir', |
||
| 136 | 'round', |
||
| 137 | 'scandir', |
||
| 138 | 'sprintf', |
||
| 139 | 'str_replace', |
||
| 140 | 'strip_tags', |
||
| 141 | 'strlen', |
||
| 142 | 'strpos', |
||
| 143 | 'strtotime', |
||
| 144 | 'strval', |
||
| 145 | 'substr', |
||
| 146 | 'symlink', |
||
| 147 | 'time', |
||
| 148 | 'trigger_error', |
||
| 149 | 'trim', |
||
| 150 | 'ucfirst', |
||
| 151 | 'unlink', |
||
| 152 | 'version_compare', |
||
| 153 | 'mb_strtoupper', |
||
| 154 | 'mb_strtolower', |
||
| 155 | 'mb_strpos', |
||
| 156 | 'mb_strlen', |
||
| 157 | 'mb_strrpos', |
||
| 158 | ]; |
||
| 159 | |||
| 160 | // xoops functions |
||
| 161 | $functions[] = [ |
||
| 162 | 'xoops_getHandler', |
||
| 163 | 'xoops_load', |
||
| 164 | 'xoops_loadLanguage', |
||
| 165 | ]; |
||
| 166 | // xoops const |
||
| 167 | $constants[] = [ |
||
| 168 | 'XOBJ_DTYPE_', |
||
| 169 | 'XOOPS_URL', |
||
| 170 | 'XOOPS_ROOT_PATH', |
||
| 171 | 'XOOPS_GROUP_', |
||
| 172 | ]; |
||
| 173 | |||
| 174 | $moduleNameUpper = \mb_strtoupper($moduleName); |
||
| 175 | // module language defines |
||
| 176 | $constants[] = [ |
||
| 177 | '_AM_' . $moduleNameUpper .'_', |
||
| 178 | '_MI_' . $moduleNameUpper .'_', |
||
| 179 | '_MB_' . $moduleNameUpper .'_', |
||
| 180 | '_MA_' . $moduleNameUpper .'_', |
||
| 181 | ]; |
||
| 182 | |||
| 183 | // repair known errors |
||
| 184 | $errors = [ |
||
| 185 | 'strto\time(' => 'strtotime(', |
||
| 186 | 'mb_\strlen(' => 'mb_strlen(', |
||
| 187 | 'mb_\substr(' => 'mb_substr(', |
||
| 188 | 'x\copy' => 'xcopy', |
||
| 189 | 'r\rmdir' => 'rrmdir', |
||
| 190 | 'r\copy' => 'rcopy', |
||
| 191 | '\dirname()' => 'dirname()', |
||
| 192 | 'assw\ord' => 'assword', |
||
| 193 | 'mb_\strpos' => 'mb_strpos', |
||
| 194 | 'image\copy(' => 'imagecopy(', |
||
| 195 | '<{if \count(' => '<{if count(', |
||
| 196 | 'define(\_' => 'define(_', |
||
| 197 | "'\_AM_" . $moduleNameUpper .'_' => "'_AM_" . $moduleNameUpper .'_', |
||
| 198 | "'\_MI_" . $moduleNameUpper .'_' => "'_MI_" . $moduleNameUpper .'_', |
||
| 199 | "'\_MB_" . $moduleNameUpper .'_' => "'_MB_" . $moduleNameUpper .'_', |
||
| 200 | "'\_MA_" . $moduleNameUpper .'_' => "'_MA_" . $moduleNameUpper .'_', |
||
| 201 | ]; |
||
| 202 | |||
| 203 | $patterns = []; |
||
| 204 | foreach ($functions as $function) { |
||
| 205 | //reset existing in order to avoid double \\ |
||
| 206 | foreach ($function as $item) { |
||
| 207 | $patterns['\\' . $item . '('] = $item . '('; |
||
| 208 | } |
||
| 209 | //apply now for all |
||
| 210 | foreach ($function as $item) { |
||
| 211 | $patterns[$item . '('] = '\\' . $item . '('; |
||
| 212 | } |
||
| 213 | } |
||
| 214 | foreach ($constants as $constant) { |
||
| 215 | //reset existing in order to avoid double \\ |
||
| 216 | foreach ($constant as $item) { |
||
| 217 | $patterns['\\' . $item ] = $item; |
||
| 218 | } |
||
| 219 | //apply now for all |
||
| 220 | foreach ($constant as $item) { |
||
| 221 | $patterns[$item] = '\\' . $item; |
||
| 222 | } |
||
| 223 | } |
||
| 224 | |||
| 225 | //add errors |
||
| 226 | foreach ($errors as $key => $value) { |
||
| 227 | $patterns[$key] = $value; |
||
| 228 | } |
||
| 229 | |||
| 230 | $patKeys = \array_keys($patterns); |
||
| 231 | $patValues = \array_values($patterns); |
||
| 232 | Devtools::cloneFileFolder($src_path, $dst_path, $patKeys, $patValues); |
||
| 233 | |||
| 352 |
If you suppress an error, we recommend checking for the error condition explicitly: