Passed
Push — feature/experience-form-modals ( 0102f3...c8cf6b )
by Tristan
05:11 queued 13s
created

SendScreenCandidatesEmail   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 9
c 0
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A handle() 0 12 4
1
<?php
2
3
namespace App\Listeners;
4
5
use App\Events\JobSaved;
6
use App\Mail\ScreenCandidatesPrompt;
7
use App\Models\Lookup\JobPosterStatus;
8
use Illuminate\Support\Facades\Log;
9
use Illuminate\Support\Facades\Mail;
10
11
class SendScreenCandidatesEmail
12
{
13
    /**
14
     * Create the event listener.
15
     *
16
     * @return void
17
     */
18
    public function __construct()
19
    {
20
    }
21
22
    /**
23
     * Handle the event.
24
     *
25
     * @param  JobSaved  $event
26
     * @return void
27
     */
28
    public function handle(JobSaved $event)
29
    {
30
        $job = $event->job;
31
32
        $assessment = JobPosterStatus::where('key', 'assessment')->first()->id;
33
        // If the job poster status has changed to 'assessment' then send email
34
        if ($job->isDirty('job_poster_status_id') && $job->job_poster_status_id == $assessment) {
35
            $manager_email = $job->manager->user->email;
36
            if (isset($manager_email)) {
37
                Mail::to($manager_email)->send(new ScreenCandidatesPrompt($job));
38
            } else {
39
                Log::error('The screen applicants email to manager has not been set.');
40
            }
41
        }
42
    }
43
}
44