Conditions | 5 |
Paths | 5 |
Total Lines | 59 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
60 | protected function cache_compressed_includes_files_single ($extension, $target_file_path, $files, $vulcanization, &$not_embedded_resources) { |
||
61 | $content = ''; |
||
62 | switch ($extension) { |
||
63 | /** |
||
64 | * Insert external elements into resulting css file. |
||
65 | * It is needed, because those files will not be copied into new destination of resulting css file. |
||
66 | */ |
||
67 | case 'css': |
||
68 | /** |
||
69 | * @param string $content |
||
70 | * @param string $file |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | $callback = function ($content, $file) use (&$not_embedded_resources) { |
||
75 | return $content.Includes_processing::css(file_get_contents($file), $file, $not_embedded_resources); |
||
76 | }; |
||
77 | break; |
||
78 | /** |
||
79 | * Combine css and js files for Web Component into resulting files in order to optimize loading process |
||
80 | */ |
||
81 | case 'html': |
||
82 | /** |
||
83 | * For CSP-compatible HTML files we need to know destination to put there additional JS/CSS files |
||
84 | * |
||
85 | * @param string $content |
||
86 | * @param string $file |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | $callback = function ($content, $file) use ($target_file_path, $vulcanization, &$not_embedded_resources) { |
||
91 | $base_target_file_path = "$target_file_path-".basename($file).'+'.substr(md5($file), 0, 5); |
||
92 | return $content.Includes_processing::html( |
||
93 | file_get_contents($file), |
||
94 | $file, |
||
95 | $base_target_file_path, |
||
96 | $vulcanization, |
||
97 | $not_embedded_resources |
||
98 | ); |
||
99 | }; |
||
100 | break; |
||
101 | case 'js': |
||
102 | /** |
||
103 | * @param string $content |
||
104 | * @param string $file |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | $callback = function ($content, $file) { |
||
109 | return $content.Includes_processing::js(file_get_contents($file)); |
||
110 | }; |
||
111 | if (substr($target_file_path, -7) == ':System') { |
||
112 | $content = 'window.cs={Language:'._json_encode(Language::instance()).'};'; |
||
113 | $content .= 'window.requirejs={paths:'._json_encode($this->get_requirejs_paths()).'};'; |
||
114 | } |
||
115 | } |
||
116 | /** @noinspection PhpUndefinedVariableInspection */ |
||
117 | return array_reduce($files, $callback, $content); |
||
118 | } |
||
119 | } |
||
120 |