Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
SendApprovedEmail
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
3 / 3
4
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
1<?php
2
3namespace App\Jobs\Email;
4
5use SendGrid\Mail\Mail;
6
7/**
8 * FIRE-1147: async wrapper for the "your quote was approved" notification.
9 * Replaces the inline SendGrid call in Quotations::send_approved_notification
10 * (Quotations.php:799-…).
11 *
12 * The controller does the synchronous work (approval recording, in-app
13 * notification creation, audit log) BEFORE dispatching this job — see the
14 * FIRE-1092 ordering comment in the controller. This job just delivers
15 * the email.
16 */
17class SendApprovedEmail extends AbstractSendgridJob
18{
19    public function __construct(
20        public readonly string $toEmail,
21        public readonly string $subject,
22        public readonly string $html,
23        public readonly ?string $quoteId = null,
24    ) {}
25
26    protected function buildMail(): ?Mail
27    {
28        if ($this->toEmail === '') {
29            return null;
30        }
31
32        $email = new Mail;
33        $email->setFrom('fire@fire.es', 'Fire Service Titan');
34        $email->setSubject($this->subject);
35        $email->addTo($this->toEmail);
36        $email->addContent('text/html', $this->html);
37
38        $imgpath = file_get_contents(public_path('fireservicetitan.png'));
39        $email->addAttachment(
40            $imgpath,
41            'image/png',
42            'fireservicetitan.png',
43            'inline',
44            'fireservicetitan'
45        );
46
47        return $email;
48    }
49
50    protected function logLabel(): string
51    {
52        return 'Quotations::send_approved_notification';
53    }
54}