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

SwiftSmtpTransportProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 53.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 30
ccs 8
cts 15
cp 0.5333
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A register() 0 13 1
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