Completed
Push — master ( 8f2113...8bcad2 )
by
unknown
12s queued 10s
created

SocketConstants::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace PhpAmqpLib\Helper;
4
5
/**
6
  * @property-read int SOCKET_EPIPE
7
 * @property-read int SOCKET_ENETDOWN
8
 * @property-read int SOCKET_ENETUNREACH
9
 * @property-read int SOCKET_ENETRESET
10
 * @property-read int SOCKET_ECONNABORTED
11
 * @property-read int SOCKET_ECONNRESET
12
 * @property-read int SOCKET_ECONNREFUSED
13
 * @property-read int SOCKET_ETIMEDOUT
14
 * @property-read int SOCKET_EWOULDBLOCK
15
 * @property-read int SOCKET_EINTR
16
 * @property-read int SOCKET_EAGAIN
17
 */
18
final class SocketConstants
19
{
20
    /**
21
     * @var int[]
22
     */
23
    private $constants;
24
25
    /** @var self */
26
    private static $instance;
27
28
    public function __construct()
29
    {
30
        $constants = get_defined_constants(true);
31
        if (isset($constants['sockets'])) {
32
            $this->constants = $constants['sockets'];
33
        } else {
34
            trigger_error('Sockets extension is not enabled', E_USER_WARNING);
35
            $this->constants = array();
36
        }
37
    }
38
39
    /**
40
     * @param string $name
41
     * @return int
42
     */
43
    public function __get($name)
44
    {
45
        return isset($this->constants[$name]) ? $this->constants[$name] : 0;
46
    }
47
48
    /**
49
     * @param string $name
50
     * @param int $value
51
     * @internal
52
     */
53
    public function __set($name, $value)
54
    {
55
    }
56
57
    /**
58
     * @param string $name
59
     * @return bool
60
     */
61
    public function __isset($name)
62
    {
63
        return isset($this->constants[$name]);
64
    }
65
66
    /**
67
     * @return self
68
     */
69
    public static function getInstance()
70
    {
71
        if (!self::$instance) {
72
            self::$instance = new self;
73
        }
74
75
        return self::$instance;
76
    }
77
}
78