Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
SendRejectedEmail
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 buildMail
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
2
 logLabel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 gateBucket
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 gateCompanyId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Jobs\Email;
4
5use App\Services\SendgridDispatcher;
6use SendGrid\Mail\Mail;
7
8/**
9 * FIRE-1147: async wrapper for the "your quote was rejected" notification.
10 * Replaces the inline SendGrid call in Quotations::send_rejected_notification
11 * (Quotations.php:1108-…) called from reject_quotation.
12 */
13class SendRejectedEmail extends AbstractSendgridJob
14{
15    public function __construct(
16        public readonly string $toEmail,
17        public readonly string $subject,
18        public readonly string $html,
19        public readonly ?string $quoteId = null,
20        /** FIRE-1930: quotation's company, checked against the approval kill switch. */
21        public readonly ?int $companyId = null,
22    ) {}
23
24    protected function buildMail(): ?Mail
25    {
26        if ($this->toEmail === '') {
27            return null;
28        }
29
30        $email = new Mail;
31        $email->setFrom('fire@fire.es', 'Fire Service Titan');
32        $email->setSubject($this->subject);
33        $email->addTo($this->toEmail);
34        $email->addContent('text/html', $this->html);
35
36        $imgpath = file_get_contents(public_path('fireservicetitan.png'));
37        $email->addAttachment(
38            $imgpath,
39            'image/png',
40            'fireservicetitan.png',
41            'inline',
42            'fireservicetitan'
43        );
44
45        return $email;
46    }
47
48    protected function logLabel(): string
49    {
50        return 'Quotations::send_rejected_notification';
51    }
52
53    protected function gateBucket(): ?string
54    {
55        return SendgridDispatcher::BUCKET_APPROVAL;
56    }
57
58    protected function gateCompanyId(): ?int
59    {
60        // ?? so a job queued before this property existed gates as null
61        // instead of reading an uninitialized readonly property.
62        return $this->companyId ?? null;
63    }
64}