Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| EmailHelper | |
100.00% |
14 / 14 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createEmail | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| createTemplatedEmail | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| createAdminEmail | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getFrom | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Service; |
| 6 | |
| 7 | use Symfony\Bridge\Twig\Mime\TemplatedEmail; |
| 8 | use Symfony\Component\DependencyInjection\Attribute\Autowire; |
| 9 | use Symfony\Component\Mime\Address; |
| 10 | use Symfony\Component\Mime\Email; |
| 11 | |
| 12 | readonly class EmailHelper |
| 13 | { |
| 14 | private Address $from; |
| 15 | |
| 16 | public function __construct( |
| 17 | #[Autowire('%env(EMAIL_FROM)%')] string $from, |
| 18 | ) |
| 19 | { |
| 20 | $this->from = Address::create($from); |
| 21 | } |
| 22 | |
| 23 | public function createEmail(Address $to, string $subject): Email |
| 24 | { |
| 25 | return new Email() |
| 26 | ->from($this->from) |
| 27 | ->to($to) |
| 28 | ->subject($subject); |
| 29 | } |
| 30 | |
| 31 | public function createTemplatedEmail(Address $to, string $subject): TemplatedEmail |
| 32 | { |
| 33 | return new TemplatedEmail() |
| 34 | ->from($this->from) |
| 35 | ->to($to) |
| 36 | ->subject($subject); |
| 37 | } |
| 38 | |
| 39 | public function createAdminEmail(string $subject): Email |
| 40 | { |
| 41 | return new Email() |
| 42 | ->from($this->from) |
| 43 | ->to($this->from) |
| 44 | ->subject($subject); |
| 45 | } |
| 46 | |
| 47 | public function getFrom(): Address |
| 48 | { |
| 49 | return $this->from; |
| 50 | } |
| 51 | } |