Test Failed
Pull Request — master (#30)
by Evgeniy
08:35
created

Mailer::getTransport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Mailer\SwiftMailer;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use RuntimeException;
9
use Swift_Events_EventListener;
10
use Swift_Mailer;
11
use Swift_Transport;
12
use Yiisoft\Mailer\Mailer as BaseMailer;
13
use Yiisoft\Mailer\MessageBodyRenderer;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Mailer\MessageBodyRenderer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Yiisoft\Mailer\MessageFactoryInterface;
15
use Yiisoft\Mailer\MessageInterface;
16
17
/**
18
 * Mailer implements a mailer based on SwiftMailer.
19
 *
20
 * @see https://swiftmailer.symfony.com
21
 */
22
final class Mailer extends BaseMailer
23
{
24
    private Swift_Mailer $swiftMailer;
25
26
    /**
27
     * @param MessageFactoryInterface $messageFactory
28
     * @param MessageBodyRenderer $messageBodyRenderer
29
     * @param EventDispatcherInterface $eventDispatcher
30
     * @param Swift_Transport $transport
31 3
     * @param Swift_Events_EventListener[] $plugins
32
     */
33 3
    public function __construct(
34
        MessageFactoryInterface $messageFactory,
35
        MessageBodyRenderer $messageBodyRenderer,
36
        EventDispatcherInterface $eventDispatcher,
37
        Swift_Transport $transport,
38
        array $plugins = []
39
    ) {
40
        parent::__construct($messageFactory, $messageBodyRenderer, $eventDispatcher);
41
        $this->swiftMailer = new Swift_Mailer($transport);
42
43 4
        foreach ($plugins as $plugin) {
44
            $this->swiftMailer->registerPlugin($plugin);
45
        }
46
    }
47
48
    protected function sendMessage(MessageInterface $message): void
49
    {
50 4
        /** @var Message $message */
51 4
        $sent = $this->swiftMailer->send($message->getSwiftMessage());
52 4
53
        if ($sent === 0) {
54 1
            throw new RuntimeException('Unable send message.');
55
        }
56
    }
57
}
58