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