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
SendApprovedEmail
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 approved" notification.
10 * Replaces the inline SendGrid call in Quotations::send_approved_notification
11 * (Quotations.php:799-…).
12 *
13 * The controller does the synchronous work (approval recording, in-app
14 * notification creation, audit log) BEFORE dispatching this job — see the
15 * FIRE-1092 ordering comment in the controller. This job just delivers
16 * the email.
17 */
18class SendApprovedEmail extends AbstractSendgridJob
19{
20    public function __construct(
21        public readonly string $toEmail,
22        public readonly string $subject,
23        public readonly string $html,
24        public readonly ?string $quoteId = null,
25        /** FIRE-1930: quotation's company, checked against the approval kill switch. */
26        public readonly ?int $companyId = null,
27    ) {}
28
29    protected function buildMail(): ?Mail
30    {
31        if ($this->toEmail === '') {
32            return null;
33        }
34
35        $email = new Mail;
36        $email->setFrom('fire@fire.es', 'Fire Service Titan');
37        $email->setSubject($this->subject);
38        $email->addTo($this->toEmail);
39        $email->addContent('text/html', $this->html);
40
41        $imgpath = file_get_contents(public_path('fireservicetitan.png'));
42        $email->addAttachment(
43            $imgpath,
44            'image/png',
45            'fireservicetitan.png',
46            'inline',
47            'fireservicetitan'
48        );
49
50        return $email;
51    }
52
53    protected function logLabel(): string
54    {
55        return 'Quotations::send_approved_notification';
56    }
57
58    protected function gateBucket(): ?string
59    {
60        return SendgridDispatcher::BUCKET_APPROVAL;
61    }
62
63    protected function gateCompanyId(): ?int
64    {
65        // ?? so a job queued before this property existed gates as null
66        // instead of reading an uninitialized readonly property.
67        return $this->companyId ?? null;
68    }
69}