Conditions | 13 |
Paths | 177 |
Total Lines | 86 |
Code Lines | 27 |
Lines | 10 |
Ratio | 11.63 % |
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\View; |
||
216 | public function getOverloadPath(View $view) |
||
217 | { |
||
218 | |||
219 | /* |
||
220 | * We can only overload namespaced |
||
221 | * views right now. |
||
222 | */ |
||
223 | if (!str_contains($view->getName(), '::')) { |
||
224 | return null; |
||
225 | } |
||
226 | |||
227 | /* |
||
228 | * Split the view into it's |
||
229 | * namespace and path. |
||
230 | */ |
||
231 | list($namespace, $path) = explode('::', $view->getName()); |
||
232 | |||
233 | $override = null; |
||
234 | |||
235 | $path = str_replace('.', '/', $path); |
||
236 | |||
237 | /* |
||
238 | * If the namespace is shorthand |
||
239 | * then check to see if we have |
||
240 | * an active addon to use for it. |
||
241 | */ |
||
242 | if ($namespace === 'module' && $this->module) { |
||
243 | $namespace = $this->module->getNamespace(); |
||
244 | } |
||
245 | |||
246 | if ($namespace === 'theme' && $this->theme) { |
||
247 | $namespace = $this->theme->getNamespace(); |
||
248 | } |
||
249 | |||
250 | /* |
||
251 | * If the view is a streams view then |
||
252 | * it's real easy to guess what the |
||
253 | * override path should be. |
||
254 | */ |
||
255 | if ($namespace == 'streams') { |
||
256 | $path = $this->theme->getNamespace('streams/' . $path); |
||
257 | } |
||
258 | |||
259 | /* |
||
260 | * If the view uses a dot syntax namespace then |
||
261 | * transform it all into the override view path. |
||
262 | */ |
||
263 | View Code Duplication | if ($addon = $this->addons->get($namespace)) { |
|
264 | $override = $this->theme->getNamespace( |
||
265 | "addons/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/" . $path |
||
266 | ); |
||
267 | } |
||
268 | |||
269 | if ($this->view->exists($override)) { |
||
270 | return $override; |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * Check if a published override exists. |
||
275 | */ |
||
276 | if ($addon) { |
||
277 | $override = "app::addons/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/views/" . $path; |
||
278 | } |
||
279 | |||
280 | if ($this->view->exists($override)) { |
||
281 | return $override; |
||
282 | } |
||
283 | |||
284 | /* |
||
285 | * If the view uses a dot syntax namespace then |
||
286 | * transform it all into the override view path. |
||
287 | * |
||
288 | * @deprecated since v3.0.0 |
||
289 | */ |
||
290 | View Code Duplication | if ($addon) { |
|
291 | $override = $this->theme->getNamespace( |
||
292 | "addon/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/" . $path |
||
293 | ); |
||
294 | } |
||
295 | |||
296 | if ($this->view->exists($override)) { |
||
297 | return $override; |
||
298 | } |
||
299 | |||
300 | return null; |
||
301 | } |
||
302 | } |
||
303 |