NetworkConnection::getAddress()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Dazzle\Http;
4
5
use Dazzle\Socket\SocketInterface;
6
7
class NetworkConnection implements NetworkConnectionInterface
8
{
9
    /**
10
     * @var SocketInterface
11
     */
12
    protected $conn;
13
14
    /**
15
     * @param SocketInterface $conn
16
     */
17 22
    public function __construct(SocketInterface $conn)
18
    {
19 22
        $this->conn = $conn;
20 22
    }
21
22
    /**
23
     *
24
     */
25 15
    public function __destruct()
26
    {
27 15
        unset($this->conn);
28 15
    }
29
30
    /**
31
     * @override
32
     * @inheritDoc
33
     */
34 1
    public function getResourceId()
35
    {
36 1
        return $this->conn->getResourceId();
37
    }
38
39
    /**
40
     * @override
41
     * @inheritDoc
42
     */
43 1
    public function getEndpoint()
44
    {
45 1
        return $this->conn->getRemoteEndpoint();
46
    }
47
48
    /**
49
     * @override
50
     * @inheritDoc
51
     */
52 3
    public function getAddress()
53
    {
54 3
        return $this->conn->getRemoteAddress();
55
    }
56
57
    /**
58
     * @override
59
     * @inheritDoc
60
     */
61 1
    public function getHost()
62
    {
63 1
        $address = explode(':', $this->getAddress());
64
65 1
        return $address[0];
66
    }
67
68
    /**
69
     * @override
70
     * @inheritDoc
71
     */
72 1
    public function getPort()
73
    {
74 1
        $address = explode(':', $this->getAddress());
75
76 1
        return $address[1];
77
    }
78
79
    /**
80
     * @override
81
     * @inheritDoc
82
     */
83 1
    public function send($data)
84
    {
85 1
        $this->conn->write((string)$data);
86 1
    }
87
88
    /**
89
     * @override
90
     * @inheritDoc
91
     */
92 1
    public function close()
93
    {
94 1
        $this->conn->close();
95
    }
96
}