Completed
Push — master ( b92a49...e8f5e1 )
by Rasmus
12:47 queued 09:15
created

SocketConnector::connect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2.0116
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($host, $port = 25)
26
    {
27 2
        $this->host = $host;
28 2
        $this->port = $port;
29 2
    }
30
31 2
    public function connect($client_domain)
32
    {
33 2
        $socket = @fsockopen($this->host, $this->port);
34
35 2
        if (! $socket) {
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