Passed
Push — master ( cd18e5...9103a9 )
by Alexander
01:59
created

SwiftSmtpTransportProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 56.25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 19
c 1
b 0
f 0
dl 0
loc 33
ccs 9
cts 16
cp 0.5625
rs 10

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
    /**
28
     * @suppress PhanAccessMethodProtected
29
     */
30 8
    public function register(Container $container): void
31
    {
32 8
        $container->set(\Swift_Transport::class, function () {
33
            $swiftSmtpTransport = new \Swift_SmtpTransport(
34
                $this->host,
35
                $this->port,
36
                $this->encryption
37
            );
38
39
            $swiftSmtpTransport->setUsername($this->username);
40
            $swiftSmtpTransport->setPassword($this->password);
41
42
            return $swiftSmtpTransport;
43 8
        });
44 8
    }
45
}
46