Passed
Push — master ( b4e552...a91d54 )
by y
03:05
created
src/SocketInterface.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,34 +42,34 @@
 block discarded – undo
42 42
      *
43 43
      * @return int `SOCK_*`
44 44
      */
45
-    public static function getType ();
45
+    public static function getType();
46 46
 
47 47
     /**
48 48
      * Returns the address family constant of the socket.
49 49
      *
50 50
      * @return int `AF_*`
51 51
      */
52
-    public function getDomain ();
52
+    public function getDomain();
53 53
 
54 54
     /**
55 55
      * Returns the underlying socket resource as an integer.
56 56
      *
57 57
      * @return int
58 58
      */
59
-    public function getId ();
59
+    public function getId();
60 60
 
61 61
     /**
62 62
      * Returns the protocol constant used by the socket.
63 63
      *
64 64
      * @return int
65 65
      */
66
-    public function getProtocol ();
66
+    public function getProtocol();
67 67
 
68 68
     /**
69 69
      * Returns the underlying socket resource.
70 70
      *
71 71
      * @return resource
72 72
      */
73
-    public function getResource ();
73
+    public function getResource();
74 74
 
75 75
 }
76 76
\ No newline at end of file
Please login to merge, or discard this patch.
src/WebSocketServer.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      * @param $resource
24 24
      * @param Reactor $reactor
25 25
      */
26
-    public function __construct ($resource, Reactor $reactor) {
26
+    public function __construct($resource, Reactor $reactor) {
27 27
         parent::__construct($resource);
28 28
         $reactor->add($this);
29 29
         $this->reactor = $reactor;
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      * https://tools.ietf.org/html/rfc6455#section-4.2
36 36
      * @return WebSocketClient
37 37
      */
38
-    public function accept () {
38
+    public function accept() {
39 39
         if (!$resource = @socket_accept($this->resource)) {
40 40
             throw new Error($this->resource); // reliable errno
41 41
         }
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * @param WebSocketClient $client
52 52
      */
53
-    protected function acceptHandshake (WebSocketClient $client) {
53
+    protected function acceptHandshake(WebSocketClient $client) {
54 54
         $head = $client->await(self::CH_READ)->recv(4096); // todo client->readUntil(string,maxlength)
55 55
         $head = explode("\r\n", $head);
56 56
         $method = array_shift($head);
@@ -78,17 +78,17 @@  discard block
 block discarded – undo
78 78
             "HTTP/1.1 101 Switching Protocols",
79 79
             "Upgrade: websocket",
80 80
             "Connection: Upgrade",
81
-            "Sec-WebSocket-Accept: " . base64_encode(sha1($base64Key . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)),
81
+            "Sec-WebSocket-Accept: ".base64_encode(sha1($base64Key.'258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)),
82 82
         ];
83 83
 
84
-        $client->write(implode("\r\n", $response) . "\r\n\r\n");
84
+        $client->write(implode("\r\n", $response)."\r\n\r\n");
85 85
     }
86 86
 
87 87
     /**
88 88
      * @param WebSocketClient $client
89 89
      * @param string $connection
90 90
      */
91
-    protected function acceptHandshakeConnection (WebSocketClient $client, string $connection) {
91
+    protected function acceptHandshakeConnection(WebSocketClient $client, string $connection) {
92 92
         if (!preg_match('/^upgrade$/i', $connection)) {
93 93
             $this->reject($client, "Expected: Connection: Upgrade");
94 94
         }
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      * @param WebSocketClient $client
101 101
      * @param string $host
102 102
      */
103
-    protected function acceptHandshakeHost (WebSocketClient $client, string $host) {
103
+    protected function acceptHandshakeHost(WebSocketClient $client, string $host) {
104 104
 
105 105
     }
106 106
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      * @param WebSocketClient $client
109 109
      * @param string $base64Key
110 110
      */
111
-    protected function acceptHandshakeKey (WebSocketClient $client, string $base64Key) {
111
+    protected function acceptHandshakeKey(WebSocketClient $client, string $base64Key) {
112 112
         $key = base64_decode($base64Key);
113 113
         if ($key === false or strlen($key) !== 16) {
114 114
             $this->reject($client, "Expected Sec-WebSocket-Key");
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      * @param WebSocketClient $client
120 120
      * @param string $method
121 121
      */
122
-    protected function acceptHandshakeMethod (WebSocketClient $client, string $method) {
122
+    protected function acceptHandshakeMethod(WebSocketClient $client, string $method) {
123 123
         if (!preg_match('/HTTP\/1\.1$/i', $method)) {
124 124
             $this->reject($client, "Expected: HTTP/1.1");
125 125
         }
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      * @param WebSocketClient $client
132 132
      * @param string $origin
133 133
      */
134
-    protected function acceptHandshakeOrigin (WebSocketClient $client, string $origin) {
134
+    protected function acceptHandshakeOrigin(WebSocketClient $client, string $origin) {
135 135
 
136 136
     }
137 137
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      * @param WebSocketClient $client
140 140
      * @param string $upgrade
141 141
      */
142
-    protected function acceptHandshakeUpgrade (WebSocketClient $client, string $upgrade) {
142
+    protected function acceptHandshakeUpgrade(WebSocketClient $client, string $upgrade) {
143 143
         if (!preg_match('/^websocket$/i', $upgrade)) {
144 144
             $this->reject($client, "Expected Upgrade: websocket");
145 145
         }
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      * @param WebSocketClient $client
150 150
      * @param string $version
151 151
      */
152
-    protected function acceptHandshakeVersion (WebSocketClient $client, string $version) {
152
+    protected function acceptHandshakeVersion(WebSocketClient $client, string $version) {
153 153
         if ($version !== '13') {
154 154
             $this->reject($client, "Expected Sec-WebSocket-Version: 13");
155 155
         }
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
     /**
159 159
      * @return WebSocketClient[]
160 160
      */
161
-    public function getClients () {
161
+    public function getClients() {
162 162
         return $this->clients;
163 163
     }
164 164
 
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      * @param resource $resource
167 167
      * @return WebSocketClient
168 168
      */
169
-    protected function newClient ($resource) {
169
+    protected function newClient($resource) {
170 170
         return new WebSocketClient($resource, $this);
171 171
     }
172 172
 
@@ -175,14 +175,14 @@  discard block
 block discarded – undo
175 175
      *
176 176
      * @inheritDoc
177 177
      */
178
-    final public function onOutOfBand () {
178
+    final public function onOutOfBand() {
179 179
         // do nothing
180 180
     }
181 181
 
182 182
     /**
183 183
      * @inheritDoc
184 184
      */
185
-    public function onReadable () {
185
+    public function onReadable() {
186 186
         $this->accept();
187 187
     }
188 188
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      * @param string $reason
194 194
      * @throws RuntimeException
195 195
      */
196
-    protected function reject (WebSocketClient $client, string $reason) {
196
+    protected function reject(WebSocketClient $client, string $reason) {
197 197
         throw new RuntimeException("Rejected {$client}: {$reason}");
198 198
     }
199 199
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      * @param WebSocketClient $client
204 204
      * @return $this
205 205
      */
206
-    public function remove (WebSocketClient $client) {
206
+    public function remove(WebSocketClient $client) {
207 207
         unset($this->clients[$client->getId()]);
208 208
         $this->reactor->remove($client->getId());
209 209
         return $this;
Please login to merge, or discard this patch.
src/WebSocketClient.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
      * @param $resource
19 19
      * @param WebSocketServer $server
20 20
      */
21
-    public function __construct ($resource, WebSocketServer $server) {
21
+    public function __construct($resource, WebSocketServer $server) {
22 22
         parent::__construct($resource);
23 23
         $this->server = $server;
24 24
     }
@@ -26,33 +26,33 @@  discard block
 block discarded – undo
26 26
     /**
27 27
      * Removes the client from the server and reactor.
28 28
      */
29
-    protected function onClose () {
29
+    protected function onClose() {
30 30
         $this->server->remove($this);
31 31
     }
32 32
 
33 33
     /**
34 34
      * @param string $payload
35 35
      */
36
-    protected function onData (string $payload): void {
36
+    protected function onData(string $payload): void {
37 37
     }
38 38
 
39 39
     /**
40 40
      * WebSockets do not use the out-of-band channel.
41 41
      */
42
-    final public function onOutOfBand () {
42
+    final public function onOutOfBand() {
43 43
     }
44 44
 
45 45
     /**
46 46
      * When a browser responds to a ping.
47 47
      */
48
-    protected function onPong (): void {
48
+    protected function onPong(): void {
49 49
         // stub
50 50
     }
51 51
 
52 52
     /**
53 53
      * Reads framed messages.
54 54
      */
55
-    public function onReadable (): void {
55
+    public function onReadable(): void {
56 56
         $data = $this->recv(4096);
57 57
         $frame = new WebSocketFrame($data);
58 58
         if ($frame->isText()) {
@@ -74,17 +74,17 @@  discard block
 block discarded – undo
74 74
      *
75 75
      * @param string $text
76 76
      */
77
-    protected function onText (string $text): void {
77
+    protected function onText(string $text): void {
78 78
     }
79 79
 
80 80
     /**
81 81
      * Pings the browser.
82 82
      */
83
-    public function ping () {
83
+    public function ping() {
84 84
         $this->write(WebSocketFrame::pack('', WebSocketFrame::OP_PING));
85 85
     }
86 86
 
87
-    public function writeText (string $message) {
87
+    public function writeText(string $message) {
88 88
         $packed = WebSocketFrame::pack($message);
89 89
         $this->write($packed);
90 90
     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -57,14 +57,11 @@
 block discarded – undo
57 57
         $frame = new WebSocketFrame($data);
58 58
         if ($frame->isText()) {
59 59
             $this->onText($frame->getPayload());
60
-        }
61
-        elseif ($frame->isBinary()) {
60
+        } elseif ($frame->isBinary()) {
62 61
             $this->onData($frame->getPayload());
63
-        }
64
-        elseif ($frame->isPong()) {
62
+        } elseif ($frame->isPong()) {
65 63
             $this->onPong();
66
-        }
67
-        elseif ($frame->isClose()) {
64
+        } elseif ($frame->isClose()) {
68 65
             $this->close();
69 66
         }
70 67
     }
Please login to merge, or discard this patch.
src/StreamServer.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      *
13 13
      * @return int
14 14
      */
15
-    final public static function getType () {
15
+    final public static function getType() {
16 16
         return SOCK_STREAM;
17 17
     }
18 18
 
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      * @throws Error
28 28
      * @return StreamClient The accepted connection, as a client instance.
29 29
      */
30
-    public function accept () {
30
+    public function accept() {
31 31
         if (!$resource = @socket_accept($this->resource)) {
32 32
             throw new Error($this->resource); // reliable errno
33 33
         }
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      * @throws Error
47 47
      * @return $this
48 48
      */
49
-    public function listen ($backlog = 0) {
49
+    public function listen($backlog = 0) {
50 50
         if (!@socket_listen($this->resource, $backlog)) {
51 51
             throw new Error($this->resource); // reliable errno
52 52
         }
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      * @return StreamClient
61 61
      * @throws Error
62 62
      */
63
-    protected function newClient ($resource) {
63
+    protected function newClient($resource) {
64 64
         return new StreamClient($resource);
65 65
     }
66 66
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      * @param StreamClient $client
71 71
      * @return void
72 72
      */
73
-    protected function onAccept (StreamClient $client) {
73
+    protected function onAccept(StreamClient $client) {
74 74
     }
75 75
 
76 76
 }
Please login to merge, or discard this patch.