| Conditions | 12 |
| Paths | 18 |
| Total Lines | 34 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 33 | public function route(string $systemName, $parameters = [], $absolute = true, $forceWithLocalePrefix = false): string |
||
| 34 | { |
||
| 35 | $parameters = array_wrap($parameters); |
||
| 36 | |||
| 37 | if (! empty($parameters[0]) && ($parameters[0] instanceof \Illuminate\Database\Eloquent\Model)) { |
||
| 38 | $entity = $parameters[0]; |
||
| 39 | if ($entity->urlAlias) { |
||
| 40 | unset($parameters[0]); |
||
| 41 | if (! $this->config->get('url-aliases.use_localization')) { |
||
| 42 | $alias = $entity->urlAlias->alias; |
||
| 43 | } elseif ($this->config->get('url-aliases-laravellocalization.origin_default_locale') == $entity->urlAlias->locale && $this->config->get('url-aliases-laravellocalization.hideDefaultLocaleInURL') && !$forceWithLocalePrefix) { |
||
| 44 | $alias = $entity->urlAlias->alias; |
||
| 45 | } else { |
||
| 46 | $alias = $entity->urlAlias->localeAlias; |
||
| 47 | } |
||
| 48 | |||
| 49 | if (count($parameters)) { |
||
| 50 | $alias .= '?' . http_build_query($parameters); |
||
| 51 | } |
||
| 52 | |||
| 53 | return $absolute ? url($alias) : $alias; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | if (!empty($this->config['url-aliases']['use_localization'])) { |
||
| 58 | $relativePath = trim(route($systemName, $parameters, false), '/'); |
||
| 59 | |||
| 60 | if ($absolute) { |
||
| 61 | return url($this->config['app']['locale'] . '/' . $relativePath); |
||
| 62 | } |
||
| 63 | return $relativePath; |
||
| 64 | } |
||
| 65 | |||
| 66 | return route($systemName, $parameters, $absolute); |
||
| 67 | } |
||
| 75 | } |