Completed
Push — master ( 083bb9...6d7292 )
by y
01:28
created
src/AbstractSocket.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @return int
16 16
      */
17
-    abstract public static function getType (): int;
17
+    abstract public static function getType(): int;
18 18
 
19 19
     /**
20 20
      * The underlying PHP resource.
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @return static
34 34
      * @throws SocketError
35 35
      */
36
-    public static function create (int $domain = AF_INET, ...$extra) {
36
+    public static function create(int $domain = AF_INET, ...$extra) {
37 37
         if (!$resource = @socket_create($domain, static::getType(), 0)) { // auto-protocol
38 38
             throw new SocketError; // reliable errno
39 39
         }
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
      * @throws InvalidArgumentException Not a socket resource, or the socket is of the wrong type.
50 50
      * @throws SocketError Slippage of an existing error on the resource.
51 51
      */
52
-    public function __construct ($resource) {
52
+    public function __construct($resource) {
53 53
         if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') {
54 54
             throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF);
55 55
         }
56 56
         elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) {
57
-            throw new InvalidArgumentException('Invalid socket type for ' . static::class, SOCKET_ESOCKTNOSUPPORT);
57
+            throw new InvalidArgumentException('Invalid socket type for '.static::class, SOCKET_ESOCKTNOSUPPORT);
58 58
         }
59 59
         elseif ($errno = SocketError::getLast($resource)) {
60 60
             // "File descriptor in bad state"
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      *
69 69
      * @see close()
70 70
      */
71
-    public function __destruct () {
71
+    public function __destruct() {
72 72
         if ($this->isOpen()) {
73 73
             $this->close();
74 74
         }
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      * @return $this
86 86
      * @throws SocketError
87 87
      */
88
-    public function await (int $channel) {
88
+    public function await(int $channel) {
89 89
         $rwe = [$channel => [$this->resource]];
90 90
         if (!@socket_select($rwe[0], $rwe[1], $rwe[2], null)) {
91 91
             throw new SocketError($this->resource);
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      *
99 99
      * @return $this
100 100
      */
101
-    final public function awaitOutOfBand () {
101
+    final public function awaitOutOfBand() {
102 102
         return $this->await(self::CH_EXCEPT);
103 103
     }
104 104
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      *
108 108
      * @return $this
109 109
      */
110
-    final public function awaitReadable () {
110
+    final public function awaitReadable() {
111 111
         return $this->await(self::CH_READ);
112 112
     }
113 113
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      *
117 117
      * @return $this
118 118
      */
119
-    final public function awaitWritable () {
119
+    final public function awaitWritable() {
120 120
         return $this->await(self::CH_WRITE);
121 121
     }
122 122
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      *
128 128
      * @return $this
129 129
      */
130
-    public function close () {
130
+    public function close() {
131 131
         if ($this->isOpen()) {
132 132
             socket_close($this->resource);
133 133
         }
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
      *
140 140
      * @return int
141 141
      */
142
-    final public function getDomain (): int {
142
+    final public function getDomain(): int {
143 143
         return $this->getOption(39); // SO_DOMAIN is not exposed by PHP
144 144
     }
145 145
 
146 146
     /**
147 147
      * @return int
148 148
      */
149
-    final public function getId (): int {
150
-        return (int)$this->resource;
149
+    final public function getId(): int {
150
+        return (int) $this->resource;
151 151
     }
152 152
 
153 153
     /**
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      * @return mixed The option's value. This is never `false`.
160 160
      * @throws SocketError
161 161
      */
162
-    public function getOption (int $option) {
162
+    public function getOption(int $option) {
163 163
         $value = @socket_get_option($this->resource, SOL_SOCKET, $option);
164 164
         if ($value === false) {
165 165
             throw new SocketError($this->resource, SOCKET_EINVAL);
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
     /**
171 171
      * @return resource
172 172
      */
173
-    final public function getResource () {
173
+    final public function getResource() {
174 174
         return $this->resource;
175 175
     }
176 176
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      * @return array `[ 0 => address, 1 => port ]`
183 183
      * @throws SocketError
184 184
      */
185
-    public function getSockName (): array {
185
+    public function getSockName(): array {
186 186
         if (!@socket_getsockname($this->resource, $addr, $port)) {
187 187
             throw new SocketError($this->resource, SOCKET_EOPNOTSUPP);
188 188
         }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     /**
193 193
      * @return bool
194 194
      */
195
-    public function isOpen (): bool {
195
+    public function isOpen(): bool {
196 196
         return is_resource($this->resource);
197 197
     }
198 198
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      *
204 204
      * @return bool
205 205
      */
206
-    final public function isOutOfBand (): bool {
206
+    final public function isOutOfBand(): bool {
207 207
         return $this->isReady(self::CH_EXCEPT);
208 208
     }
209 209
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
      *
215 215
      * @return bool
216 216
      */
217
-    final public function isReadable (): bool {
217
+    final public function isReadable(): bool {
218 218
         return $this->isReady(self::CH_READ);
219 219
     }
220 220
 
@@ -228,15 +228,15 @@  discard block
 block discarded – undo
228 228
      * @return bool
229 229
      * @throws SocketError
230 230
      */
231
-    public function isReady (int $channel, ?float $timeout = 0): bool {
231
+    public function isReady(int $channel, ?float $timeout = 0): bool {
232 232
         $rwe = [$channel => [$this->resource]];
233 233
         // core casts non-null timeout to int.
234 234
         // usec is ignored if timeout is null.
235
-        $usec = (int)(fmod($timeout, 1) * 1000000);
235
+        $usec = (int) (fmod($timeout, 1) * 1000000);
236 236
         if (false === $count = @socket_select($rwe[0], $rwe[1], $rwe[2], $timeout, $usec)) {
237 237
             throw new SocketError($this->resource);
238 238
         }
239
-        return (bool)$count;
239
+        return (bool) $count;
240 240
     }
241 241
 
242 242
     /**
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      *
247 247
      * @return bool
248 248
      */
249
-    final public function isWritable (): bool {
249
+    final public function isWritable(): bool {
250 250
         return $this->isReady(self::CH_WRITE);
251 251
     }
252 252
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
      * @return $this
271 271
      * @throws SocketError
272 272
      */
273
-    public function setBlocking (bool $blocking) {
273
+    public function setBlocking(bool $blocking) {
274 274
         if ($blocking ? @socket_set_block($this->resource) : @socket_set_nonblock($this->resource)) {
275 275
             return $this;
276 276
         }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      * @return $this
288 288
      * @throws SocketError
289 289
      */
290
-    public function setOption (int $option, $value) {
290
+    public function setOption(int $option, $value) {
291 291
         if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) {
292 292
             throw new SocketError($this->resource, SOCKET_EINVAL);
293 293
         }
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
      * @param float $timeout Zero means "no timeout" (block forever).
301 301
      * @return $this
302 302
      */
303
-    public function setTimeout (float $timeout) {
303
+    public function setTimeout(float $timeout) {
304 304
         $tv = [
305
-            'sec' => (int)$timeout,
306
-            'usec' => (int)(fmod($timeout, 1) * 1000000)
305
+            'sec' => (int) $timeout,
306
+            'usec' => (int) (fmod($timeout, 1) * 1000000)
307 307
         ];
308 308
         $this->setOption(SO_RCVTIMEO, $tv);
309 309
         $this->setOption(SO_SNDTIMEO, $tv);
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
      * @return $this
334 334
      * @throws SocketError
335 335
      */
336
-    public function shutdown (int $channel) {
336
+    public function shutdown(int $channel) {
337 337
         if (!@socket_shutdown($this->resource, $channel)) {
338 338
             throw new SocketError($this->resource); // reliable errno
339 339
         }
Please login to merge, or discard this patch.