Conditions | 3 |
Paths | 4 |
Total Lines | 57 |
Code Lines | 38 |
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 |
||
34 | public function screenCandidatesPrompt($job) // phpcs:ignore |
||
35 | { |
||
36 | // Get emails of all Hr Advisors who have claimed job |
||
37 | $hr_advisors_emails = []; |
||
38 | $hr_advisors = $job->hr_advisors; |
||
39 | |||
40 | foreach ($hr_advisors as $advisor) { |
||
41 | $email = User::where('id', $advisor->user_id)->first()->email; |
||
42 | array_push($hr_advisors_emails, $email); |
||
43 | } |
||
44 | |||
45 | // Get date 2 weeks after job poster closes |
||
46 | $dateFormat = Config::get('app.date_format'); |
||
47 | $locale = App::getLocale(); |
||
48 | $timestamp_in_two_weeks = strtotime('+2 weeks', $job->close_date_time->timestamp); |
||
49 | $date_in_two_weeks = date($dateFormat[$locale], $timestamp_in_two_weeks); |
||
50 | |||
51 | // Number of applicants |
||
52 | $num_of_applicants = $job->job_applications->count(); |
||
53 | |||
54 | // Number of non-citizens |
||
55 | $canadian_citizen = CitizenshipDeclaration::where('name', 'citizen')->first()->id; |
||
56 | $num_of_noncitizens = $job->job_applications |
||
57 | ->where('citizenship_declaration_id', '!=', $canadian_citizen) |
||
58 | ->count(); |
||
59 | |||
60 | // Number of veterans |
||
61 | $non_veteran = VeteranStatus::where('name', 'none')->first()->id; |
||
62 | $num_of_veterans = $job->job_applications |
||
63 | ->where('veteran_status_id', '!=', $non_veteran) |
||
64 | ->count(); |
||
65 | |||
66 | // Create array of data needed for ScreeningCandidatesPrompt mailable |
||
67 | $mailData = [ |
||
68 | 'classification' => $job->getClassificationMessageAttribute(), |
||
69 | 'drop_off_date' => $date_in_two_weeks, |
||
70 | 'hr_advisors_emails' => $hr_advisors_emails, |
||
71 | 'manager_portal_link' => [ |
||
72 | 'en' => route('manager.home'), |
||
|
|||
73 | 'fr' => route('manager.home'), |
||
74 | ], |
||
75 | 'num_of_applicants' => $num_of_applicants, |
||
76 | 'num_of_noncitizens' => $num_of_noncitizens, |
||
77 | 'num_of_veterans' => $num_of_veterans, |
||
78 | 'position' => $job->getTranslations('title'), |
||
79 | 'position_link' => [ |
||
80 | 'en' => route('jobs.show', $job), |
||
81 | 'fr' => route('jobs.show', $job), |
||
82 | ], |
||
83 | 'talent_cloud_email' => '[email protected]', |
||
84 | ]; |
||
85 | |||
86 | $manager_email = $job->manager->user->email; |
||
87 | if (isset($manager_email)) { |
||
88 | Mail::to($manager_email)->send(new ScreenCandidatesPrompt($mailData)); |
||
89 | } else { |
||
90 | Log::error('The screen applicants email to manager has not been set.'); |
||
91 | } |
||
107 |