| Conditions | 2 |
| Paths | 2 |
| Total Lines | 53 |
| Code Lines | 36 |
| 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 |
||
| 43 | public function build() |
||
| 44 | { |
||
| 45 | // Get emails of all Hr Advisors who have claimed job. |
||
| 46 | $hr_advisors_emails = []; |
||
| 47 | $hr_advisors = $this->job->hr_advisors; |
||
| 48 | |||
| 49 | foreach ($hr_advisors as $advisor) { |
||
| 50 | $email = User::where('id', $advisor->user_id)->first()->email; |
||
| 51 | array_push($hr_advisors_emails, $email); |
||
| 52 | } |
||
| 53 | |||
| 54 | // Get date 2 weeks after job poster closes. |
||
| 55 | $dateFormat = Config::get('app.date_format'); |
||
| 56 | $locale = App::getLocale(); |
||
| 57 | $timestamp_in_two_weeks = strtotime('+2 weeks', $this->job->close_date_time->timestamp); |
||
| 58 | $date_in_two_weeks = date($dateFormat[$locale], $timestamp_in_two_weeks); |
||
| 59 | |||
| 60 | // Number of applicants. |
||
| 61 | $num_of_applicants = $this->job->job_applications->count(); |
||
| 62 | |||
| 63 | // Number of non-citizens. |
||
| 64 | $canadian_citizen = CitizenshipDeclaration::where('name', 'citizen')->first()->id; |
||
| 65 | $num_of_noncitizens = $this->job->job_applications |
||
| 66 | ->where('citizenship_declaration_id', '!=', $canadian_citizen) |
||
| 67 | ->count(); |
||
| 68 | |||
| 69 | // Number of veterans. |
||
| 70 | $non_veteran = VeteranStatus::where('name', 'none')->first()->id; |
||
| 71 | $num_of_veterans = $this->job->job_applications |
||
| 72 | ->where('veteran_status_id', '!=', $non_veteran) |
||
| 73 | ->count(); |
||
| 74 | |||
| 75 | $position = $this->job->getTranslations('title'); |
||
| 76 | $classification = $this->job->getClassificationMessageAttribute(); |
||
| 77 | $subject = Lang::get('common/notifications/screen_candidates.subject', [ 'position' => $position['en'], 'classification' => $classification ]) . ' / ' . Lang::get('common/notifications/screen_candidates.subject', [ 'position' => $position['fr'], 'classification' => $classification ], 'fr'); |
||
| 78 | |||
| 79 | return $this->subject($subject) |
||
| 80 | ->cc($hr_advisors_emails) |
||
| 81 | ->markdown('emails.job_posters.screen_candidates_plain', [ |
||
| 82 | 'drop_off_date' => $date_in_two_weeks, |
||
| 83 | 'manager_portal_link' => [ |
||
| 84 | 'en' => Lang::get('common/notifications/screen_candidates.manager_portal_link'), |
||
| 85 | 'fr' => Lang::get('common/notifications/screen_candidates.manager_portal_link', [], 'fr'), |
||
| 86 | ], |
||
| 87 | 'num_of_applicants' => $num_of_applicants, |
||
| 88 | 'num_of_noncitizens' => $num_of_noncitizens, |
||
| 89 | 'num_of_veterans' => $num_of_veterans, |
||
| 90 | 'position' => $position, |
||
| 91 | 'position_link' => [ |
||
| 92 | 'en' => Lang::get('common/notifications/screen_candidates.position_link', ['id' => $this->job->id]), |
||
| 93 | 'fr' => Lang::get('common/notifications/screen_candidates.position_link', ['id' => $this->job->id], 'fr'), |
||
| 94 | ], |
||
| 95 | 'talent_cloud_email' => config('mail.admin_address'), |
||
|
|
|||
| 96 | ]); |
||
| 99 |