Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SendFinanceRecipientEmail
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildMail
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
20
 logLabel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Jobs\Email;
4
5use SendGrid\Mail\Mail;
6
7/**
8 * FIRE-1148: async wrapper for the per-recipient finance report send.
9 * Replaces the two inline `$sendgrid->send()` sites in
10 * SendFinanceReport::handle() — one per per-company recipient group,
11 * one per all-regions recipient.
12 *
13 * The command keeps the synchronous work (resolve recipients, fetch
14 * resumen data, render HTML); only the SendGrid roundtrip moves to
15 * the worker. Subject + HTML are pre-rendered by the command so the
16 * job stays free of finance-domain knowledge.
17 *
18 * Retries / rate limit inherited from AbstractSendgridJob: 5 tries,
19 * exp backoff, shared 'sendgrid' rate-limit bucket, 'failed_jobs' on
20 * exhaustion (FIRE-1147 infrastructure).
21 */
22class SendFinanceRecipientEmail extends AbstractSendgridJob
23{
24    public function __construct(
25        public readonly string $toEmail,
26        public readonly ?string $toName,
27        public readonly string $subject,
28        public readonly string $html,
29    ) {}
30
31    protected function buildMail(): ?Mail
32    {
33        if ($this->toEmail === '') {
34            return null;
35        }
36
37        $email = new Mail;
38        $email->setFrom('fire@fire.es', 'Fire Service Titan');
39        $email->setSubject($this->subject);
40        if ($this->toName !== null && $this->toName !== '') {
41            $email->addTo($this->toEmail, $this->toName);
42        } else {
43            $email->addTo($this->toEmail);
44        }
45        $email->addContent('text/html', $this->html);
46
47        return $email;
48    }
49
50    protected function logLabel(): string
51    {
52        return 'SendFinanceReport::handle';
53    }
54}