| Conditions | 9 |
| Paths | 16 |
| Total Lines | 52 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 81 | protected static function get_content ($files, $package_name, $package_dir, $target_dir) { |
||
| 82 | $content = []; |
||
| 83 | if ($files) { |
||
| 84 | @mkdir($target_dir, 0770, true); |
||
| 85 | file_put_contents( |
||
| 86 | "$target_dir/.htaccess", |
||
| 87 | <<<HTACCESS |
||
| 88 | <FilesMatch "\.css$"> |
||
| 89 | Header set Content-Type text/css |
||
| 90 | </FilesMatch> |
||
| 91 | HTACCESS |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | foreach ($files as $file) { |
||
| 95 | $file = "$package_dir/$file"; |
||
| 96 | switch (file_extension($file)) { |
||
| 97 | case 'js': |
||
| 98 | $content['js'][] = file_get_contents($file); |
||
| 99 | break; |
||
| 100 | case 'css': |
||
| 101 | $content['css'][] = Includes_processing::css( |
||
| 102 | file_get_contents($file), |
||
| 103 | $file |
||
| 104 | ); |
||
| 105 | break; |
||
| 106 | case 'html': |
||
| 107 | $content['html'][] = Includes_processing::html( |
||
| 108 | file_get_contents($file), |
||
| 109 | $file, |
||
| 110 | $package_name, |
||
| 111 | $target_dir |
||
| 112 | ); |
||
| 113 | break; |
||
| 114 | case 'less': |
||
| 115 | try { |
||
| 116 | $content['css'][] = Includes_processing::css( |
||
| 117 | (new Less_Parser)->parseFile($file)->getCss(), |
||
| 118 | $file |
||
| 119 | ); |
||
| 120 | } catch (Exception $e) { |
||
| 121 | } |
||
| 122 | break; |
||
| 123 | case 'scss': |
||
| 124 | $content['css'][] = Includes_processing::css( |
||
| 125 | (new Scss_compiler)->compile(file_get_contents($file)), |
||
| 126 | $file |
||
| 127 | ); |
||
| 128 | break; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | return $content; |
||
| 132 | } |
||
| 133 | /** |
||
| 147 |