| Conditions | 13 |
| Paths | 19 |
| Total Lines | 46 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 55 | public function index($slug = null) |
||
| 56 | { |
||
| 57 | if ($slug == null) { |
||
| 58 | $page = $this->page->where('isHp', 1)->firstOrFail(); |
||
| 59 | } elseif ($slug !== null) { |
||
| 60 | $redirect = $this->redirect->where('slug', $slug)->first(); |
||
| 61 | if ($redirect !== null) { |
||
| 62 | return redirect($redirect->to, $redirect->type); |
||
| 63 | } |
||
| 64 | |||
| 65 | $repeater = $this->repeater->where('url', $slug)->first(); |
||
| 66 | if ($repeater !== null) { |
||
| 67 | $templateHintpath = explode('::', (string) $repeater->page)[0]; |
||
| 68 | $template = $this->template->where('active', 1)->where('hintpath', $templateHintpath)->first(); |
||
| 69 | |||
| 70 | return view((string) $repeater->page, compact('template', 'repeater')); |
||
| 71 | } |
||
| 72 | |||
| 73 | $page = $this->page->where('slug->'.app()->getLocale(), $slug)->first(); |
||
| 74 | if ($page == null) { |
||
| 75 | foreach (\LaravelLocalization::getSupportedLocales() as $localeCode => $properties) { |
||
| 76 | $page = $this->page->where('slug->'.$localeCode, $slug)->first(); |
||
| 77 | if ($page !== null && $localeCode == app()->getLocale()) { |
||
| 78 | break; |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($page !== null && $localeCode !== app()->getLocale()) { |
||
| 82 | //dd(app()->getLocale()); |
||
| 83 | app()->setLocale($localeCode); |
||
| 84 | \LaravelLocalization::setLocale($localeCode); |
||
| 85 | |||
| 86 | return redirect($localeCode.'/'.$slug); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($page == null) { |
||
| 92 | abort(404); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | if ($page->roles !== null) { |
||
| 97 | return $this->authorizedIndex($page); |
||
| 98 | } |
||
| 99 | |||
| 100 | return $this->getView($page); |
||
| 101 | } |
||
| 183 |