Passed
Push — master ( 66fdc9...e2b180 )
by Alexander
08:00 queued 05:21
created

SwiftSmtpTransportProvider::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.6699

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
ccs 1
cts 8
cp 0.125
crap 1.6699
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Provider;
6
7
use Yiisoft\Di\Container;
8
use Yiisoft\Di\Support\ServiceProvider;
9
10
final class SwiftSmtpTransportProvider extends ServiceProvider
11
{
12
    private string $host;
13
    private int $port;
14
    private ?string $encryption;
15
    private string $username;
16
    private string $password;
17
18 8
    public function __construct(string $host, int $port, ?string $encryption, string $username, string $password)
19
    {
20 8
        $this->host = $host;
21 8
        $this->port = $port;
22 8
        $this->encryption = $encryption;
23 8
        $this->username = $username;
24 8
        $this->password = $password;
25 8
    }
26
27 8
    public function register(Container $container): void
28
    {
29
        $container->set(\Swift_Transport::class, function () {
30
            $swiftSmtpTransport = new \Swift_SmtpTransport(
31
                $this->host,
32
                $this->port,
33
                $this->encryption
34
            );
35
36
            $swiftSmtpTransport->setUsername($this->username);
37
            $swiftSmtpTransport->setPassword($this->password);
38
39
            return $swiftSmtpTransport;
40 8
        });
41 8
    }
42
}
43