Connection::from()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Socket connection
4
 * User: moyo
5
 * Date: 04/08/2017
6
 * Time: 12:25 PM
7
 */
8
9
namespace Carno\Socket;
10
11
use Carno\Net\Connection as NET;
12
use Carno\Net\Contracts\TCP;
13
use Carno\Socket\Contracts\Stream;
14
15
class Connection extends NET implements Stream
16
{
17
    /**
18
     * @var TCP
19
     */
20
    private $sock = null;
21
22
    /**
23
     * @var string
24
     */
25
    private $data = null;
26
27
    /**
28
     * @param TCP $sock
29
     * @return Stream
30
     */
31
    public function from(TCP $sock) : Stream
32
    {
33
        $this->sock = $sock;
34
        return $this;
35
    }
36
37
    /**
38
     * @param string $data
39
     * @return self
40
     */
41
    public function setReceived(string $data) : self
42
    {
43
        $this->data = $data;
44
        return $this;
45
    }
46
47
    /**
48
     *
49
     * @return string
50
     */
51
    public function recv() : string
52
    {
53
        return $this->data;
54
    }
55
56
    /**
57
     * @param string $data
58
     * @return bool
59
     */
60
    public function write(string $data) : bool
61
    {
62
        return $this->sock->write($data, $this->id);
63
    }
64
65
    /**
66
     * @param string $data
67
     * @return bool
68
     */
69
    public function send(string $data) : bool
70
    {
71
        return $this->sock->send($data, $this->id);
72
    }
73
74
    /**
75
     * @return bool
76
     */
77
    public function close() : bool
78
    {
79
        return $this->sock->close($this->id);
80
    }
81
}
82