| Conditions | 5 |
| Paths | 4 |
| Total Lines | 54 |
| Code Lines | 40 |
| 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 |
||
| 139 | public function outputCombinedHeaderCSS(string $controller, string $action){ |
||
| 140 | |||
| 141 | $CSSCachePath = appPath('sites/admin-cabinet/assets/css/cache').'/'.$this->version; |
||
| 142 | if (!is_dir($CSSCachePath)){ |
||
| 143 | mkdir($CSSCachePath, 0755, true); |
||
| 144 | } |
||
| 145 | |||
| 146 | $headerJSCollections = [ |
||
| 147 | 'SemanticUICSS', |
||
| 148 | 'headerCSS' |
||
| 149 | ]; |
||
| 150 | |||
| 151 | $combinedCSSFilePath = "{$CSSCachePath}/{$controller}-{$action}.css"; |
||
| 152 | if (!file_exists($combinedCSSFilePath)){ |
||
| 153 | file_put_contents($combinedCSSFilePath, '', LOCK_EX); |
||
| 154 | foreach ($headerJSCollections as $collectionName){ |
||
| 155 | file_put_contents($combinedCSSFilePath, '/* Data collection '.$collectionName.'*/'.PHP_EOL.PHP_EOL, FILE_APPEND | LOCK_EX); |
||
| 156 | foreach ($this->collection($collectionName) as $resource) { |
||
| 157 | file_put_contents($combinedCSSFilePath, '/* CSS file '.$resource->getPath().'*/'.PHP_EOL.PHP_EOL, FILE_APPEND | LOCK_EX); |
||
| 158 | $sourceCSSPath = appPath('sites/admin-cabinet/assets/').$resource->getPath(); |
||
| 159 | $sourceCSSContent = file_get_contents($sourceCSSPath); |
||
| 160 | $sourceCSSContent = str_replace( |
||
| 161 | [ './themes/default/assets/fonts/', |
||
| 162 | 'url(icons.woff)', |
||
| 163 | 'url(icons.woff2)', |
||
| 164 | 'url(outline-icons.woff2)', |
||
| 165 | 'url(outline-icons.woff)', |
||
| 166 | 'url(brand-icons.woff2)', |
||
| 167 | 'url(brand-icons.woff)', |
||
| 168 | 'url(../themes/default/assets/images/flags.png)', |
||
| 169 | 'font/lato-v15-latin', |
||
| 170 | 'font/lato-v14-latin', |
||
| 171 | ], |
||
| 172 | [ |
||
| 173 | './../vendor/themes/default/assets/fonts/', |
||
| 174 | 'url("./../vendor/themes/default/assets/fonts/icons.woff")', |
||
| 175 | 'url("./../vendor/themes/default/assets/fonts/icons.woff2")', |
||
| 176 | 'url("./../vendor/themes/default/assets/fonts/outline-icons.woff2")', |
||
| 177 | 'url("./../vendor/themes/default/assets/fonts/outline-icons.woff")', |
||
| 178 | 'url("./../vendor/themes/default/assets/fonts/brand-icons.woff2")', |
||
| 179 | 'url("./../vendor/themes/default/assets/fonts/brand-icons.woff")', |
||
| 180 | 'url(./../../vendor/themes/default/assets/images/flags.png)', |
||
| 181 | './../../vendor/semantic/font/lato-v15-latin', |
||
| 182 | './../../vendor/semantic/font/lato-v14-latin' |
||
| 183 | ], |
||
| 184 | $sourceCSSContent |
||
| 185 | ); |
||
| 186 | file_put_contents($combinedCSSFilePath, $sourceCSSContent,FILE_APPEND | LOCK_EX); |
||
| 187 | file_put_contents($combinedCSSFilePath, PHP_EOL.PHP_EOL, FILE_APPEND | LOCK_EX); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | return "<link rel='stylesheet' type='text/css' href='/admin-cabinet/assets/css/cache/{$this->version}/{$controller}-{$action}.css?ver=".$this->version."'>"; |
||
| 193 | |||
| 195 | } |