| Conditions | 12 |
| Paths | 22 |
| Total Lines | 69 |
| Code Lines | 30 |
| Lines | 10 |
| Ratio | 14.49 % |
| 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 namespace Anomaly\Streams\Platform\Image; |
||
| 127 | public function outputPath(Image $image) |
||
| 128 | { |
||
| 129 | $path = $image->getImage(); |
||
| 130 | |||
| 131 | if ($path instanceof FileInterface) { |
||
| 132 | $path = $path->path(); |
||
| 133 | } |
||
| 134 | |||
| 135 | /* |
||
| 136 | * If the path is already public |
||
| 137 | * then just use it as it is. |
||
| 138 | */ |
||
| 139 | if (str_contains($path, public_path())) { |
||
| 140 | return str_replace(public_path(), '', $path); |
||
| 141 | } |
||
| 142 | |||
| 143 | /* |
||
| 144 | * If the path is a file or file path then |
||
| 145 | * put it in /app/{$application}/files/disk/folder/filename.ext |
||
| 146 | */ |
||
| 147 | if (is_string($path) && str_is('*://*', $path)) { |
||
| 148 | |||
| 149 | $application = $this->application->getReference(); |
||
| 150 | |||
| 151 | list($disk, $folder, $filename) = explode('/', str_replace('://', '/', $path)); |
||
| 152 | |||
| 153 | View Code Duplication | if ($image->getAlterations() || $image->getQuality()) { |
|
| 154 | $filename = md5( |
||
| 155 | var_export([$path, $image->getAlterations()], true) . $image->getQuality() |
||
| 156 | ) . '.' . $image->getExtension(); |
||
| 157 | } |
||
| 158 | |||
| 159 | if ($rename = $image->getFilename()) { |
||
| 160 | |||
| 161 | $filename = $rename; |
||
| 162 | |||
| 163 | if (strpos($filename, DIRECTORY_SEPARATOR)) { |
||
| 164 | $directory = null; |
||
| 165 | } |
||
| 166 | } |
||
| 167 | |||
| 168 | return "/app/{$application}/files/{$disk}/{$folder}/{$filename}"; |
||
| 169 | } |
||
| 170 | |||
| 171 | /* |
||
| 172 | * Get the real path relative to our installation. |
||
| 173 | */ |
||
| 174 | $path = str_replace(base_path(), '', $this->realPath($path)); |
||
| 175 | |||
| 176 | /* |
||
| 177 | * Build out path parts. |
||
| 178 | */ |
||
| 179 | $filename = basename($path); |
||
| 180 | $directory = ltrim(dirname($path), '/\\') . '/'; |
||
| 181 | $application = $this->application->getReference(); |
||
| 182 | |||
| 183 | View Code Duplication | if ($image->getAlterations() || $image->getQuality()) { |
|
| 184 | $filename = md5( |
||
| 185 | var_export([$path, $image->getAlterations()], true) . $image->getQuality() |
||
| 186 | ) . '.' . $image->getExtension(); |
||
| 187 | } |
||
| 188 | |||
| 189 | if ($rename = $image->getFilename()) { |
||
| 190 | $directory = null; |
||
| 191 | $filename = ltrim($rename, '/\\'); |
||
| 192 | } |
||
| 193 | |||
| 194 | return "/app/{$application}/assets/{$directory}{$filename}"; |
||
| 195 | } |
||
| 196 | } |
||
| 197 |