Conditions | 17 |
Paths | 1 |
Total Lines | 38 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
65 | protected function parseSegments() |
||
66 | { |
||
67 | return collect($this->request->segments())->mapWithKeys(function ($segment, $key) { |
||
|
|||
68 | // Replaces any segment ID in url with the objects name or title. |
||
69 | if ($this->request->jobPoster === $segment) { |
||
70 | $poster = JobPoster::find($this->request->jobPoster); |
||
71 | if ($poster !== null) { |
||
72 | $segment = $poster->title; |
||
73 | } |
||
74 | } elseif (is_object($this->request->jobPoster) && $this->request->jobPoster->id == $segment) { |
||
75 | $segment = $this->request->jobPoster->title; |
||
76 | } |
||
77 | if ($this->request->manager === $segment) { |
||
78 | $poster = Manager::find($this->request->manager); |
||
79 | if ($poster !== null) { |
||
80 | $segment = $poster->title; |
||
81 | } |
||
82 | } elseif (is_object($this->request->manager) && $this->request->manager->id == $segment) { |
||
83 | $segment = $this->request->manager->title; |
||
84 | } |
||
85 | if ($this->request->applicant === $segment) { |
||
86 | $poster = Applicant::find($this->request->applicant); |
||
87 | if ($poster !== null) { |
||
88 | $segment = $poster->title; |
||
89 | } |
||
90 | } elseif (is_object($this->request->applicant) && $this->request->applicant->id == $segment) { |
||
91 | $segment = $this->request->applicant->title; |
||
92 | } |
||
93 | if ($this->request->application === $segment) { |
||
94 | $poster = JobApplication::find($this->request->application); |
||
95 | if ($poster !== null) { |
||
96 | $segment = $poster->title; |
||
97 | } |
||
98 | } elseif (is_object($this->request->application) && $this->request->application->id == $segment) { |
||
99 | $segment = $this->request->application->title; |
||
100 | } |
||
101 | return [ |
||
102 | $segment => implode('/', array_slice($this->request->segments(), 0, $key + 1)), |
||
103 | ]; |
||
107 |