Protocol   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 35
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 3 1
A __construct() 0 3 1
A write() 0 3 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