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