BaseConnection   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 62
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __destruct() 0 4 1
A setHost() 0 4 1
A setPort() 0 4 1
B connect() 0 6 5
1
<?php
2
namespace Disque\Connection;
3
4
abstract class BaseConnection implements ConnectionInterface
5
{
6
    /**
7
     * Host
8
     *
9
     * @var string
10
     */
11
    protected $host;
12
13
    /**
14
     * Port
15
     *
16
     * @var int
17
     */
18
    protected $port;
19
20
    /**
21
     * Create a new connection defaulting to localhost:7711
22
     *
23
     * @param string $host Host
24
     * @param int $port Port
25
     */
26
    public function __construct($host = 'localhost', $port = 7711)
27
    {
28
        $this->setHost($host);
29
        $this->setPort($port);
30
    }
31
32
    /**
33
     * Make sure the connection is closed
34
     */
35
    public function __destruct()
36
    {
37
        $this->disconnect();
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function setHost($host)
44
    {
45
        $this->host = $host;
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function setPort($port)
52
    {
53
        $this->port = $port;
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59
    public function connect($connectionTimeout = null, $responseTimeout = null)
60
    {
61
        if (!isset($this->host) || !is_string($this->host) || !isset($this->port) || !is_int($this->port)) {
62
            throw new ConnectionException('Invalid host or port specified');
63
        }
64
    }
65
}
66