SocketConnector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 35
ccs 10
cts 11
cp 0.9091
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A connect() 0 13 2
1
<?php
2
3
namespace Kodus\Mail\SMTP\Connector;
4
5
use Kodus\Mail\SMTP\SMTPClient;
6
use Kodus\Mail\SMTP\SMTPConnector;
7
use Kodus\Mail\SMTP\SMTPException;
8
9
class SocketConnector implements SMTPConnector
10
{
11
    /**
12
     * @var string SMTP hostname
13
     */
14
    protected $host;
15
16
    /**
17
     * @var int SMTP server port-number
18
     */
19
    protected $port;
20
21
    /**
22
     * @param string $host SMTP host-name
23
     * @param int    $port SMTP port-number
24
     */
25 2
    public function __construct(string $host, int $port = 25)
26
    {
27 2
        $this->host = $host;
28 2
        $this->port = $port;
29 2
    }
30
31 2
    public function connect(string $client_domain): SMTPClient
32
    {
33 2
        $socket = @fsockopen($this->host, $this->port);
34
35 2
        if (! $socket) {
0 ignored issues
show
introduced by
$socket is of type false|resource, thus it always evaluated to false.
Loading history...
36
            throw new SMTPException("Could not open SMTP Port.");
37
        }
38
39 2
        $client = new SMTPClient($socket);
40
41 2
        $client->sendEHLO($client_domain);
42
43 2
        return $client;
44
    }
45
}
46