| Conditions | 11 |
| Paths | 16 |
| Total Lines | 58 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 73 | protected function compileAssets() |
||
| 74 | { |
||
| 75 | $cssPath = BASE_DIR . join(DIRECTORY_SEPARATOR, ['web', 'css', 'style.min.css']); |
||
|
|
|||
| 76 | $jsPath = BASE_DIR . join(DIRECTORY_SEPARATOR, ['web', 'js', 'scripts.min.js']); |
||
| 77 | $pluginCssFiles = $this->container->getParameter('plugins.css.files'); |
||
| 78 | $pluginJsFiles = $this->container->getParameter('plugins.js.files'); |
||
| 79 | |||
| 80 | if (!file_exists($cssPath)) { |
||
| 81 | foreach ($pluginCssFiles as $viewport => $viewportCssFiles) { |
||
| 82 | /** @var Compiler $compiler */ |
||
| 83 | $compiler = $this->container->get('scssphp.compiler'); |
||
| 84 | |||
| 85 | $importPaths = []; |
||
| 86 | $scss = ''; |
||
| 87 | |||
| 88 | foreach ($viewportCssFiles as $viewportCssFile) { |
||
| 89 | if (file_exists($viewportCssFile)) { |
||
| 90 | $scss .= file_get_contents($viewportCssFile); |
||
| 91 | $importPaths[] = dirname($viewportCssFile); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | $compiler->setImportPaths($importPaths); |
||
| 96 | $compiler->setFormatter('Leafo\ScssPhp\Formatter\Compressed'); |
||
| 97 | $css = $compiler->compile($scss); |
||
| 98 | |||
| 99 | if ($viewport == 'backend') { |
||
| 100 | $cssPath = str_replace('min.css', 'backend.min.css', $cssPath); |
||
| 101 | } |
||
| 102 | |||
| 103 | file_put_contents($cssPath, $css); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | if (!file_exists($jsPath)) { |
||
| 108 | foreach ($pluginJsFiles as $viewport => $viewportJsFiles) { |
||
| 109 | /** @var JSqueeze $compiler */ |
||
| 110 | $compiler = $this->container->get('jsqueeze.compiler'); |
||
| 111 | $rawJs = ''; |
||
| 112 | |||
| 113 | foreach ($viewportJsFiles as $viewportJsFile) { |
||
| 114 | if (file_exists($viewportJsFile)) { |
||
| 115 | $rawJs .= file_get_contents($viewportJsFile); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | $minifiedJs = $compiler->squeeze( |
||
| 120 | $rawJs, |
||
| 121 | true, // $singleLine |
||
| 122 | true, // $keepImportantComments |
||
| 123 | true // $specialVarRx |
||
| 124 | ); |
||
| 125 | |||
| 126 | if ($viewport == 'backend') { |
||
| 127 | $jsPath = str_replace('min.js', 'backend.min.js', $jsPath); |
||
| 128 | } |
||
| 129 | |||
| 130 | file_put_contents($jsPath, $minifiedJs); |
||
| 131 | } |
||
| 134 | } |