GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( aee46c...48b3b3 )
by Dominic
02:09
created

Socket   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 85.71%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 69
ccs 18
cts 21
cp 0.8571
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A open() 0 4 2
A write() 0 12 3
A close() 0 8 3
1
<?php
2
3
namespace Vend\Statsd;
4
5
class Socket
6
{
7
    /**
8
     * Being fairly conservative here:
9
     *
10
     *  Implementations of the IP protocol are not required to be capable of handling arbitrarily large packets. In
11
     *  theory, the maximum possible IP packet size is 65,535 octets, but the standard only requires that implementations
12
     *  support at least 576 octets.
13
     *
14
     * via http://stackoverflow.com/a/3712822/10831
15
     *
16
     * Over this limit, we'll just fragment at the application layer, and send more than one packet.
17
     */
18
    const MAX_DATAGRAM_SIZE = 500;
19
20
    protected $host;
21
    protected $port;
22
    protected $socket = null;
23
24
    /**
25
     * Socket constructor
26
     *
27
     * @param string $host
28
     * @param int    $port
29
     */
30 3
    public function __construct($host = '127.0.0.1', $port = 8125)
31
    {
32 3
        $this->host = $host;
33 3
        $this->port = $port;
34 3
        $this->socket = null;
35 3
    }
36
37
    /**
38
     * @return void
39
     */
40 1
    public function open()
41
    {
42 1
        $this->socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP) ?: null;
43 1
    }
44
45
    /**
46
     * @param string $data
47
     * @return int|null Number of bytes written
48
     */
49 1
    public function write($data)
50
    {
51 1
        if (!$this->socket) {
52
            $this->open();
53
        }
54
55 1
        if (!$this->socket) {
56
            return null;
57
        }
58
59 1
        return socket_sendto($this->socket, $data, strlen($data), 0, $this->host, $this->port);
60
    }
61
62
    /**
63
     * Closes the socket
64
     */
65 1
    public function close()
66
    {
67 1
        if ($this->socket && is_resource($this->socket)) {
68 1
            socket_close($this->socket);
69 1
        }
70
71 1
        $this->socket = null;
72 1
    }
73
}
74