Protocol::write()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Socket RW
4
 * User: moyo
5
 * Date: 08/01/2018
6
 * Time: 2:51 PM
7
 */
8
9
namespace Carno\HTTP\Powered\Native\Parser;
10
11
class Protocol
12
{
13
    public const CRLF = "\r\n";
14
    public const SPLIT = self::CRLF.self::CRLF;
15
16
    /**
17
     * @var resource
18
     */
19
    private $fd = null;
20
21
    /**
22
     * Socket constructor.
23
     * @param $resource
24
     */
25
    public function __construct($resource)
26
    {
27
        $this->fd = $resource;
28
    }
29
30
    /**
31
     * @param int $size
32
     * @return string
33
     */
34
    public function read(int $size) : string
35
    {
36
        return stream_socket_recvfrom($this->fd, $size);
37
    }
38
39
    /**
40
     * @param string $data
41
     * @return int
42
     */
43
    public function write(string $data) : int
44
    {
45
        return stream_socket_sendto($this->fd, $data);
46
    }
47
}
48