Completed
Push — master ( 3ff097...503b9d )
by Frederik
06:54
created

SslConnection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 55
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A upgrade() 0 4 1
A connect() 0 15 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol;
5
6
/**
7
 * Class SslConnection
8
 * @package Genkgo\Mail\Protocol
9
 * @codeCoverageIgnore
10
 */
11
final class SslConnection extends AbstractConnection
12
{
13
    /**
14
     * @var string
15
     */
16
    private $host;
17
    /**
18
     * @var int
19
     */
20
    private $port;
21
    /**
22
     * @var SecureConnectionOptions
23
     */
24
    private $options;
25
26
    /**
27
     * PlainTcpConnection constructor.
28
     * @param string $host
29
     * @param int $port
30
     * @param SecureConnectionOptions $options
31
     */
32
    public function __construct(string $host, int $port, SecureConnectionOptions $options)
33
    {
34
        $this->host = $host;
35
        $this->port = $port;
36
        $this->options = $options;
37
    }
38
39
    /**
40
     * @param int $type
41
     */
42
    public function upgrade(int $type): void
43
    {
44
        throw new \InvalidArgumentException('Cannot upgrade TLS connection, already encrypted');
45
    }
46
47
    /**
48
     *
49
     */
50
    public function connect(): void
51
    {
52
        $this->resource = @stream_socket_client(
53
            'ssl://' . $this->host . ':' . $this->port,
54
            $errorCode,
55
            $errorMessage,
56
            $this->options->getTimeout()
57
        );
58
59
        if ($this->resource === false) {
60
            throw new \RuntimeException(sprintf(
61
                'Could not create resource: %s', $errorMessage), $errorCode
62
            );
63
        }
64
    }
65
}