Passed
Push — feature/screen-candidates-emai... ( 7a1461 )
by Yonathan
04:14
created

SendScreenCandidatesEmail::handle()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 4
nc 3
nop 1
1
<?php
2
3
namespace App\Listeners;
4
5
use App\Events\JobSaved;
6
use App\Mail\ScreenCandidatesPrompt;
7
use Illuminate\Support\Facades\Log;
8
use Illuminate\Support\Facades\Mail;
9
10
class SendScreenCandidatesEmail
11
{
12
    /**
13
     * Create the event listener.
14
     *
15
     * @return void
16
     */
17
    public function __construct()
18
    {
19
    }
20
21
    /**
22
     * Handle the event.
23
     *
24
     * @param  JobSaved  $event
25
     * @return void
26
     */
27
    public function handle(JobSaved $event)
28
    {
29
        $job = $event->job;
30
31
        // If the job poster status has changed to 'assessment' then send email
32
        if ($job->isDirty('job_poster_status_id') && $job->job_poster_status->key === 'assessment') {
33
            $manager_email = $job->manager->user->email;
34
            if (isset($manager_email)) {
35
                Mail::to($manager_email)->send(new ScreenCandidatesPrompt($job));
36
            } else {
37
                Log::error('The screen applicants email to manager has not been set.');
38
            }
39
        }
40
    }
41
}
42