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::__destruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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