Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
LogTransport
100.00% covered (success)
100.00%
13 / 13
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
 doSend
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
2
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Mail\Transport;
6
7use Psr\Log\LoggerInterface;
8use Symfony\Component\Mailer\SentMessage;
9use Symfony\Component\Mailer\Transport\AbstractTransport;
10
11class LogTransport extends AbstractTransport
12{
13    public function __construct(protected LoggerInterface $logger)
14    {
15
16        parent::__construct();
17    }
18
19    /**
20     * Send the message to log
21     */
22    protected function doSend(SentMessage $message): void
23    {
24        $recipients = [];
25        $messageRecipients = $message->getEnvelope()->getRecipients();
26        foreach ($messageRecipients as $recipient) {
27            $recipients[] = $recipient->toString();
28        }
29
30        $this->logger->debug(
31            'Mail: Send mail to "{recipients}":' . PHP_EOL . PHP_EOL . '{content}',
32            [
33                'recipients' => implode(', ', $recipients),
34                'content'    => $message->toString(),
35            ]
36        );
37    }
38
39    public function __toString(): string
40    {
41        return 'log://';
42    }
43}