SecureSocketConnector::connect()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 9
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Kodus\Mail\SMTP\Connector;
4
5
use Kodus\Mail\SMTP\SMTPClient;
6
use Kodus\Mail\SMTP\SMTPException;
7
8
class SecureSocketConnector extends SocketConnector
9
{
10
    /**
11
     * @var int
12
     */
13
    private $crypto_method;
14
15
    /**
16
     * @param string $host          SMTP SSL host-name
17
     * @param int    $port          SMTP port-number
18
     * @param int    $crypto_method one of the STREAM_CRYPTO_METHOD_* constants (defined by PHP)
19
     *
20
     * @see stream_socket_enable_crypto()
21
     */
22
    public function __construct(string $host, int $port = 25, int $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT)
23
    {
24
        parent::__construct($host, $port);
25
26
        $this->crypto_method = $crypto_method;
27
    }
28
29
    /**
30
     * @throws SMTPException
31
     */
32
    public function connect(string $client_domain): SMTPClient
33
    {
34
        $client = parent::connect($client_domain);
35
36
        $client->sendSTARTTLS($this->crypto_method);
37
38
        $client->sendEHLO($client_domain);
39
40
        return $client;
41
    }
42
}
43