Conditions | 19 |
Paths | 1 |
Total Lines | 41 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
64 | protected function parseSegments() |
||
65 | { |
||
66 | return collect($this->request->segments())->mapWithKeys(function ($segment, $key) { |
||
|
|||
67 | // Replaces any segment ID in url with the objects name or title. |
||
68 | if ($this->request->jobPoster == $segment) { |
||
69 | $poster = JobPoster::find($this->request->jobPoster); |
||
70 | if ($poster != null) { |
||
71 | $segment = $poster->title; |
||
72 | } |
||
73 | } elseif (is_object($this->request->jobPoster) && $this->request->jobPoster->id == $segment) { |
||
74 | $segment = $this->request->jobPoster->title; |
||
75 | } |
||
76 | if ($this->request->manager == $segment) { |
||
77 | $manager = Manager::find($this->request->manager); |
||
78 | if ($manager != null) { |
||
79 | $segment = $manager->user->full_name; |
||
80 | } |
||
81 | } elseif (is_object($this->request->manager) && $this->request->manager->id == $segment) { |
||
82 | $segment = $this->request->manager->user->full_name; |
||
83 | } |
||
84 | if ($this->request->applicant == $segment) { |
||
85 | $applicant = Applicant::find($this->request->applicant); |
||
86 | if ($applicant != null) { |
||
87 | $segment = $applicant->user->full_name; |
||
88 | } |
||
89 | } elseif (is_object($this->request->applicant) && $this->request->applicant->id == $segment) { |
||
90 | $segment = $this->request->applicant->user->full_name; |
||
91 | } |
||
92 | // A Manager or HR Advisor viewing an application cares about the Applicant name. |
||
93 | // An applicant viewing their own application cares about the job it came from. |
||
94 | if ($this->request->application == $segment) { |
||
95 | $application = JobApplication::find($this->request->application); |
||
96 | if ($application != null) { |
||
97 | $segment = WhichPortal::isApplicantPortal() ? $application->job_poster->title : $application->user_name; |
||
98 | } |
||
99 | } elseif (is_object($this->request->application) && $this->request->application->id == $segment) { |
||
100 | $application = $this->request->application; |
||
101 | $segment = WhichPortal::isApplicantPortal() ? $application->job_poster->title : $application->user_name; |
||
102 | } |
||
103 | return [ |
||
104 | $segment => implode('/', array_slice($this->request->segments(), 0, $key + 1)), |
||
105 | ]; |
||
109 |