Conditions | 14 |
Paths | 195 |
Total Lines | 47 |
Code Lines | 32 |
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 |
||
19 | static function get_requirejs_paths () { |
||
20 | $vendor_dir = STORAGE.'/Composer/vendor'; |
||
21 | $paths = []; |
||
22 | $directories = array_merge( |
||
23 | get_files_list("$vendor_dir/bower-asset", false, 'd', true), |
||
24 | get_files_list("$vendor_dir/npm-asset", false, 'd', true) |
||
25 | ); |
||
26 | foreach ($directories as $module_dir) { |
||
27 | $module_name = basename($module_dir); |
||
28 | $relative_module_dir = 'storage'.substr($module_dir, strlen(STORAGE)); |
||
29 | // Hopefully, bower.json is present and contains necessary information |
||
30 | $bower = @file_get_json("$module_dir/bower.json"); |
||
31 | foreach (@(array)$bower['main'] as $main) { |
||
32 | if (preg_match('/\.js$/', $main)) { |
||
33 | $main = substr($main, 0, -3); |
||
34 | // There is a chance that minified file is present |
||
35 | if (file_exists("$module_dir/$main.min.js")) { |
||
36 | $main .= '.min'; |
||
37 | } |
||
38 | if (file_exists("$module_dir/$main.js")) { |
||
39 | $paths[$module_name] = "$relative_module_dir/$main"; |
||
40 | continue 2; |
||
41 | } |
||
42 | } |
||
43 | } |
||
44 | // If not - try package.json from npm |
||
45 | $package = @file_get_json("$module_dir/package.json"); |
||
46 | // If we have browser-specific declaration - use it |
||
47 | $main = @$package['browser'] ?: (@$package['jspm']['main'] ?: @$package['main']); |
||
48 | if (preg_match('/\.js$/', $main)) { |
||
49 | $main = substr($main, 0, -3); |
||
50 | } |
||
51 | if ($main) { |
||
52 | // There is a chance that minified file is present |
||
53 | if (file_exists("$module_dir/$main.min.js")) { |
||
54 | $paths[$module_name] = "$relative_module_dir/$main.min"; |
||
55 | } elseif (file_exists("$module_dir/$main.js")) { |
||
56 | $paths[$module_name] = "$relative_module_dir/$main"; |
||
57 | } elseif (file_exists("$module_dir/dist/$main.min.js")) { |
||
58 | $paths[$module_name] = "$relative_module_dir/dist/$main.min"; |
||
59 | } elseif (file_exists("$module_dir/dist/$main.js")) { |
||
60 | $paths[$module_name] = "$relative_module_dir/dist/$main"; |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | return $paths; |
||
65 | } |
||
66 | /** |
||
187 |