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