Passed
Push — feature/screen-candidates-emai... ( cb6bad...e0463b )
by Yonathan
05:18
created

SendScreenCandidatesEmail::screenCandidatesPrompt()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 57
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 57
rs 9.312
cc 3
nc 4
nop 1

How to fix   Long Method   

Long Method

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:

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