Conditions | 5 |
Paths | 5 |
Total Lines | 59 |
Code Lines | 24 |
Lines | 0 |
Ratio | 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 |
||
96 | protected function cache_compressed_includes_files_single ($extension, $target_file_path, $files, $vulcanization, &$not_embedded_resources) { |
||
97 | $content = ''; |
||
98 | switch ($extension) { |
||
99 | /** |
||
100 | * Insert external elements into resulting css file. |
||
101 | * It is needed, because those files will not be copied into new destination of resulting css file. |
||
102 | */ |
||
103 | case 'css': |
||
104 | /** |
||
105 | * @param string $content |
||
106 | * @param string $file |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | $callback = function ($content, $file) use (&$not_embedded_resources) { |
||
111 | return $content.Includes_processing::css(file_get_contents($file), $file, $not_embedded_resources); |
||
112 | }; |
||
113 | break; |
||
114 | /** |
||
115 | * Combine css and js files for Web Component into resulting files in order to optimize loading process |
||
116 | */ |
||
117 | case 'html': |
||
118 | /** |
||
119 | * For CSP-compatible HTML files we need to know destination to put there additional JS/CSS files |
||
120 | * |
||
121 | * @param string $content |
||
122 | * @param string $file |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | $callback = function ($content, $file) use ($target_file_path, $vulcanization, &$not_embedded_resources) { |
||
127 | $base_target_file_path = "$target_file_path-".basename($file).'+'.substr(md5($file), 0, 5); |
||
128 | return $content.Includes_processing::html( |
||
129 | file_get_contents($file), |
||
130 | $file, |
||
131 | $base_target_file_path, |
||
132 | $vulcanization, |
||
133 | $not_embedded_resources |
||
134 | ); |
||
135 | }; |
||
136 | break; |
||
137 | case 'js': |
||
138 | /** |
||
139 | * @param string $content |
||
140 | * @param string $file |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | $callback = function ($content, $file) { |
||
145 | return $content.Includes_processing::js(file_get_contents($file)); |
||
146 | }; |
||
147 | if (substr($target_file_path, -7) == ':System') { |
||
148 | $content = 'window.cs={Language:'._json_encode(Language::instance()).'};'; |
||
149 | $content .= 'window.requirejs={paths:'._json_encode($this->get_requirejs_paths()).'};'; |
||
150 | } |
||
151 | } |
||
152 | /** @noinspection PhpUndefinedVariableInspection */ |
||
153 | return array_reduce($files, $callback, $content); |
||
154 | } |
||
155 | } |
||
156 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.