| Conditions | 5 |
| Paths | 5 |
| Total Lines | 53 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 43 | protected function cache_compressed_includes_files_single ($extension, $target_file_path, $files, $vulcanization) { |
||
| 44 | $content = ''; |
||
| 45 | switch ($extension) { |
||
| 46 | /** |
||
| 47 | * Insert external elements into resulting css file. |
||
| 48 | * It is needed, because those files will not be copied into new destination of resulting css file. |
||
| 49 | */ |
||
| 50 | case 'css': |
||
| 51 | /** |
||
| 52 | * @param string $content |
||
| 53 | * @param string $file |
||
| 54 | * |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | $callback = function ($content, $file) { |
||
| 58 | return $content.Includes_processing::css(file_get_contents($file), $file); |
||
| 59 | }; |
||
| 60 | break; |
||
| 61 | /** |
||
| 62 | * Combine css and js files for Web Component into resulting files in order to optimize loading process |
||
| 63 | */ |
||
| 64 | case 'html': |
||
| 65 | /** |
||
| 66 | * For CSP-compatible HTML files we need to know destination to put there additional JS/CSS files |
||
| 67 | * |
||
| 68 | * @param string $content |
||
| 69 | * @param string $file |
||
| 70 | * |
||
| 71 | * @return string |
||
| 72 | */ |
||
| 73 | $callback = function ($content, $file) use ($target_file_path, $vulcanization) { |
||
| 74 | $base_target_file_path = "$target_file_path-".basename($file).'+'.substr(md5($file), 0, 5); |
||
| 75 | return $content.Includes_processing::html(file_get_contents($file), $file, $base_target_file_path, $vulcanization); |
||
| 76 | }; |
||
| 77 | break; |
||
| 78 | case 'js': |
||
| 79 | /** |
||
| 80 | * @param string $content |
||
| 81 | * @param string $file |
||
| 82 | * |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | $callback = function ($content, $file) { |
||
| 86 | return $content.Includes_processing::js(file_get_contents($file)); |
||
| 87 | }; |
||
| 88 | if (substr($target_file_path, -7) == ':System') { |
||
| 89 | $content = 'window.cs={Language:'._json_encode(Language::instance()).'};'; |
||
| 90 | $content .= 'window.requirejs={paths:'._json_encode($this->get_requirejs_paths()).'};'; |
||
|
1 ignored issue
–
show
|
|||
| 91 | } |
||
| 92 | } |
||
| 93 | /** @noinspection PhpUndefinedVariableInspection */ |
||
| 94 | return array_reduce($files, $callback, $content); |
||
| 95 | } |
||
| 96 | } |
||
| 97 |
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
Idableprovides a methodequalsIdthat 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.