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