SmtpTransport   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 51
ccs 13
cts 13
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getScheme() 0 5 2
A getInstance() 0 9 2
1
<?php
2
3
namespace Da\Mailer\Transport;
4
5
use Symfony\Component\Mailer\Transport\Dsn;
6
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
7
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory;
8
9
class SmtpTransport implements TransportInterface
10
{
11
    /**
12
     * @var EsmtpTransport
13
     */
14
    private $instance;
15
/**
16
     * @var string the mail server host name or ip
17
     */
18
    private $host;
19
/**
20
     * @var int the mail server port
21
     */
22
    private $port;
23
/**
24
     * @var array the extra options for the Smtp transport -ie username, password, encryption, authMode
25
     */
26
    private $options = [];
27
/**
28
     * SmtpTransport constructor.
29
     *
30
     * @param string $host the mail server name or ip address
31
     * @param int $port the mail server port
32 2
     * @param array $options the extra options
33
     */
34 2
    public function __construct($host = 'localhost', $port = 25, $options = [])
35 2
    {
36 2
        $this->host = $host;
37 2
        $this->port = $port;
38
        $this->options = $options;
39
    }
40
41
    /**
42
     * @return EsmtpTransport
43
     */
44 1
    public function getInstance(): EsmtpTransport
45
    {
46 1
        if ($this->instance === null) {
47 1
            $user = $this->options['username'] ?? null;
48 1
            $password = $this->options['password'] ?? null;
49 1
            $this->instance = (new EsmtpTransportFactory())->create(new Dsn('smtp', $this->host, $user, $password, $this->port, $this->options));
50 1
        }
51 1
52
        return $this->instance;
53 1
    }
54
55
    private function getScheme()
0 ignored issues
show
Unused Code introduced by
The method getScheme() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
56
    {
57
        return $this->options['tls']
58
            ? 'smtps'
59
            : 'smtp';
60
    }
61
}
62