Passed
Push — task/add-applicants-and-applic... ( 514472...36c932 )
by Yonathan
10:54 queued 12s
created

MicroReferenceMail::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Mail;
4
5
use App\Models\JobApplication;
6
use App\Traits\ApiMailable;
7
use Illuminate\Bus\Queueable;
8
use Illuminate\Mail\Mailable;
9
use Illuminate\Queue\SerializesModels;
10
use Illuminate\Contracts\Queue\ShouldQueue;
11
use Illuminate\Support\Facades\Lang;
12
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
13
14
class MicroReferenceMail extends Mailable implements ShouldQueue
15
{
16
    use Queueable, SerializesModels, ApiMailable;
17
18
    /**
19
     * The application for which we need to make a reference check.
20
     *
21
     * @var \App\Models\JobApplication
22
     */
23
    public $application;
24
25
    /**
26
     * If true, this is for the applicant's Director reference.
27
     * If false, this is for the applicant's secondary reference.
28
     *
29
     * @var boolean
30
     */
31
    public $is_director;
32
33
34
35
    public function __construct(JobApplication $application, bool $is_director)
36
    {
37
        $this->application = $application;
38
        $this->is_director = $is_director;
39
    }
40
41
    /**
42
     * Build the message.
43
     *
44
     * @return $this
45
     */
46
    public function build()
47
    {
48
        $essential_criteria = $this->application->job_poster->criteria->where('criteria_type.name', 'essential');
49
        $reference_email = $this->is_director
50
            ? $this->application->director_email
51
            : $this->application->reference_email;
52
        $reference_name = $this->is_director
53
            ? $this->application->director_name
54
            : $this->application->reference_name;
55
        $mail = $this->subject(Lang::get('manager/micro_reference_mail.subject'))
56
            ->from(config('mail.from.address'), config('mail.from.name'))
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
            ->from(/** @scrutinizer ignore-call */ config('mail.from.address'), config('mail.from.name'))
Loading history...
57
            ->markdown('emails.micro_reference', [
58
                'reference_name' => $reference_name,
59
                'homepage_url' => route('response.index'),
0 ignored issues
show
Bug introduced by
The function route was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
                'homepage_url' => /** @scrutinizer ignore-call */ route('response.index'),
Loading history...
60
                'homepage_url_fr' => LaravelLocalization::getLocalizedURL('fr', route('response.index')),
61
                'applicant_name' => $this->application->applicant->user->full_name,
62
                'is_director' => $this->is_director,
63
                'criteria' => $essential_criteria,
64
            ]);
65
        if (isset($reference_email)) {
66
            $mail->to($reference_email, $reference_name ?? null);
67
        }
68
        return $mail;
69
    }
70
}
71