| Conditions | 28 |
| Paths | 1564 |
| Total Lines | 103 |
| Code Lines | 73 |
| 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 |
||
| 147 | public function loadFile($filePath, $subDir = null) |
||
| 148 | { |
||
| 149 | $directories = loader()->getPublicDirs(true); |
||
| 150 | $filePath = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $filePath); |
||
| 151 | |||
| 152 | // set filepaths |
||
| 153 | foreach ($directories as $directory) { |
||
| 154 | $extension = pathinfo($directory . $filePath, PATHINFO_EXTENSION); |
||
| 155 | |||
| 156 | if(empty($extension) and empty($subDir)) { |
||
| 157 | $extensions = ['.css', '.js']; |
||
| 158 | } elseif(empty($extension) and isset($subDir)) { |
||
| 159 | switch ($subDir) { |
||
| 160 | default: |
||
| 161 | case 'css/': |
||
| 162 | $property = 'css'; |
||
| 163 | $extensions = ['.css']; |
||
| 164 | break; |
||
| 165 | case 'font/': |
||
| 166 | case 'fonts/': |
||
| 167 | $property = 'font'; |
||
| 168 | $extensions = ['.css']; |
||
| 169 | break; |
||
| 170 | case 'js/': |
||
| 171 | case 'javascript/': |
||
| 172 | case 'javascripts/': |
||
| 173 | $property = 'javascript'; |
||
| 174 | $extensions = ['.js']; |
||
| 175 | break; |
||
| 176 | } |
||
| 177 | } else { |
||
| 178 | // remove filename extension |
||
| 179 | $filePath = str_replace('.' . $extension, '', $filePath); |
||
| 180 | switch ($extension) { |
||
| 181 | default: |
||
| 182 | case 'css': |
||
| 183 | $property = 'css'; |
||
| 184 | $subDir = 'css' . DIRECTORY_SEPARATOR; |
||
| 185 | $extensions = ['.css']; |
||
| 186 | break; |
||
| 187 | case 'font': |
||
| 188 | $property = 'font'; |
||
| 189 | $subDir = 'fonts' . DIRECTORY_SEPARATOR; |
||
| 190 | $extensions = ['.css']; |
||
| 191 | break; |
||
| 192 | case 'js': |
||
| 193 | case 'javascript': |
||
| 194 | $property = 'javascript'; |
||
| 195 | $subDir = 'js' . DIRECTORY_SEPARATOR; |
||
| 196 | $extensions = ['.js']; |
||
| 197 | break; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | foreach($extensions as $extension) { |
||
| 202 | // without subdirectory |
||
| 203 | if (input()->env('DEBUG_STAGE') === 'PRODUCTION') { |
||
| 204 | $filePaths[] = $directory . $filePath . '.min' . $extension; // minify version support |
||
| 205 | } |
||
| 206 | |||
| 207 | $filePaths[] = $directory . $filePath . $extension; |
||
| 208 | |||
| 209 | // with subdirectory |
||
| 210 | if (isset($subDir)) { |
||
| 211 | if (input()->env('DEBUG_STAGE') === 'PRODUCTION') { |
||
| 212 | $filePaths[] = $directory . $subDir . $filePath . '.min' . $extension; // minify version support |
||
| 213 | } |
||
| 214 | |||
| 215 | $filePaths[] = $directory . $subDir . $filePath . $extension; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | } |
||
| 219 | |||
| 220 | foreach ($filePaths as $filePath) { |
||
| 221 | if (is_file($filePath)) { |
||
| 222 | if(empty($property)) { |
||
| 223 | $extension = pathinfo($filePath, PATHINFO_EXTENSION); |
||
| 224 | switch ($extension) { |
||
| 225 | case 'font': |
||
| 226 | $extension = 'font'; |
||
| 227 | break; |
||
| 228 | case 'js': |
||
| 229 | $extension = 'javascript'; |
||
| 230 | break; |
||
| 231 | default: |
||
| 232 | case 'css': |
||
| 233 | $extension = 'css'; |
||
| 234 | break; |
||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 238 | if (property_exists($this, $property)) { |
||
| 239 | if ( ! call_user_func_array([$this->{$property}, 'has'], [$filePath])) { |
||
| 240 | $this->{$property}->append($filePath); |
||
| 241 | |||
| 242 | return true; |
||
| 243 | break; |
||
| 244 | } |
||
| 245 | } |
||
| 246 | } |
||
| 247 | } |
||
| 248 | |||
| 249 | return false; |
||
| 250 | } |
||
| 283 | } |