Completed
Push — main ( 083b32...2bbe13 )
by Michael
15s queued 12s
created

MailerTestTransport::getMails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Licensed under MIT. See file /LICENSE.
7
 */
8
9
namespace App\Service;
10
11
use Symfony\Component\Mailer\Envelope;
12
use Symfony\Component\Mailer\SentMessage;
13
use Symfony\Component\Mailer\Transport\TransportInterface;
14
use Symfony\Component\Mime\Email;
15
use Symfony\Component\Mime\RawMessage;
16
17
class MailerTestTransport implements TransportInterface
18
{
19
    protected static array $mails = [];
20
21
    public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
22
    {
23
        if (null === $envelope) {
24
            if ($message instanceof Email) {
25
                $envelope = new Envelope(
26
                    $message->getSender() ?? $message->getFrom()[0],
27
                    \array_merge(
28
                        $message->getTo(),
29
                        $message->getCC(),
30
                        $message->getBcc(),
31
                    )
32
                );
33
            }
34
        }
35
        $sentMessage = new SentMessage($message, $envelope);
0 ignored issues
show
Bug introduced by
It seems like $envelope can also be of type null; however, parameter $envelope of Symfony\Component\Mailer...tMessage::__construct() does only seem to accept Symfony\Component\Mailer\Envelope, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $sentMessage = new SentMessage($message, /** @scrutinizer ignore-type */ $envelope);
Loading history...
36
        self::$mails[] = $sentMessage;
37
        return $sentMessage;
38
    }
39
40
    public function reset(): void
41
    {
42
        self::$mails = [];
43
    }
44
45
    public function getMails(): array
46
    {
47
        return self::$mails;
48
    }
49
50
    public function count(): int
51
    {
52
        return \count(self::$mails);
53
    }
54
55
    public function __toString(): string
56
    {
57
        return 'testonly';
58
    }
59
}
60