| @@ -95,7 +95,7 @@ discard block | ||
| 95 | 95 | // Data is now stored in the message, let's clean the variable to stop both loops. | 
| 96 | 96 | $data = null; | 
| 97 | 97 | } | 
| 98 | - } while(!$message->isComplete() && !empty($data)); | |
| 98 | + } while (!$message->isComplete() && !empty($data)); | |
| 99 | 99 | |
| 100 | 100 |                  if ($message->isComplete()) { | 
| 101 | 101 | $this->processHelper($message, $socket); | 
| @@ -118,7 +118,7 @@ discard block | ||
| 118 | 118 | $socket->end(); | 
| 119 | 119 | $data = ''; | 
| 120 | 120 | } | 
| 121 | - } while(!empty($data)); | |
| 121 | + } while (!empty($data)); | |
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | 124 | /** | 
| @@ -63,7 +63,7 @@ | ||
| 63 | 63 | public function add(string $name, $value) | 
| 64 | 64 |      { | 
| 65 | 65 |          if (!empty($this->headers[$name])) { | 
| 66 | -            if (!\is_array($this->headers[$name])){ | |
| 66 | +            if (!\is_array($this->headers[$name])) { | |
| 67 | 67 | $this->headers[$name] = [$this->headers[$name]]; | 
| 68 | 68 | } | 
| 69 | 69 | $this->headers[$name][] = $value; | 
| @@ -38,7 +38,7 @@ | ||
| 38 | 38 |      { | 
| 39 | 39 | // Doesn't log everything in not debug context | 
| 40 | 40 |          if ($this->debug || \in_array($level, [LogLevel::CRITICAL, LogLevel::ERROR])) { | 
| 41 | -            echo '[' . date('Y-m-d H:i:s') . '][' . $level . '] ' . $message ."\n"; | |
| 41 | +            echo '[' . date('Y-m-d H:i:s') . '][' . $level . '] ' . $message . "\n"; | |
| 42 | 42 | } | 
| 43 | 43 | } | 
| 44 | 44 | } | 
| @@ -96,7 +96,7 @@ | ||
| 96 | 96 | |
| 97 | 97 |              if (\count($explodingHeader)) { | 
| 98 | 98 | unset($explodingHeader[0]); // removing the name of the extension | 
| 99 | -                foreach($explodingHeader as $variable) { | |
| 99 | +                foreach ($explodingHeader as $variable) { | |
| 100 | 100 |                      $explodeVariable = \explode('=', $variable); | 
| 101 | 101 | |
| 102 | 102 | // The value can be with or without quote. We need to remove extra quotes. | 
| @@ -98,7 +98,7 @@ discard block | ||
| 98 | 98 | $stringResponse = $this->getHttpVersion() . ' ' . $this->httpResponse . "\r\n"; | 
| 99 | 99 | |
| 100 | 100 |          foreach ($this->getHeaders() as $name => $content) { | 
| 101 | - $stringResponse .= $name . ': '. $content . "\r\n"; | |
| 101 | + $stringResponse .= $name . ': ' . $content . "\r\n"; | |
| 102 | 102 | } | 
| 103 | 103 | |
| 104 | 104 | // No content to concatenate | 
| @@ -152,7 +152,7 @@ discard block | ||
| 152 | 152 |      { | 
| 153 | 153 |          $httpElements = \explode(' ', $firstLine); | 
| 154 | 154 | |
| 155 | -        if (!\preg_match('/HTTP\/[1-2\.]+/',$httpElements[0])) { | |
| 155 | +        if (!\preg_match('/HTTP\/[1-2\.]+/', $httpElements[0])) { | |
| 156 | 156 | throw Response::createNotHttpException($firstLine); | 
| 157 | 157 | } | 
| 158 | 158 | $response->setHttpVersion($httpElements[0]); | 
| @@ -31,7 +31,7 @@ discard block | ||
| 31 | 31 | |
| 32 | 32 | $key = ''; | 
| 33 | 33 |          for ($i = 0; $i < 16; $i++) {
 | 
| 34 | - $key .= chr(mt_rand(0,255)); | |
| 34 | + $key .= chr(mt_rand(0, 255)); | |
| 35 | 35 | } | 
| 36 | 36 | |
| 37 | 37 | $key = base64_encode($key); | 
| @@ -110,7 +110,7 @@ discard block | ||
| 110 | 110 |      {
 | 
| 111 | 111 | $bytes = ''; | 
| 112 | 112 | |
| 113 | -        for($i = 0; $i < 16; $i++) {
 | |
| 113 | +        for ($i = 0; $i < 16; $i++) {
 | |
| 114 | 114 | $bytes .= chr(mt_rand(0, 255)); | 
| 115 | 115 | } | 
| 116 | 116 | |
| @@ -24,7 +24,6 @@ | ||
| 24 | 24 | use Nekland\Woketo\Rfc6455\MessageProcessor; | 
| 25 | 25 | use Nekland\Woketo\Utils\SimpleLogger; | 
| 26 | 26 | use Psr\Log\LoggerInterface; | 
| 27 | -use Psr\Log\LogLevel; | |
| 28 | 27 | use React\EventLoop\LoopInterface; | 
| 29 | 28 | use React\Socket\ConnectionInterface; | 
| 30 | 29 | use React\Socket\ServerInterface; | 
| @@ -102,7 +102,7 @@ discard block | ||
| 102 | 102 | $this->buildMessageProcessor(); | 
| 103 | 103 | |
| 104 | 104 | // Some optimization | 
| 105 | - \gc_enable(); // As the process never stops, the garbage collector will be usefull, you may need to call it manually sometimes for performance purpose | |
| 105 | + \gc_enable(); // As the process never stops, the garbage collector will be usefull, you may need to call it manually sometimes for performance purpose | |
| 106 | 106 | \set_time_limit(0); // It's by default on most server for cli apps but better be sure of that fact | 
| 107 | 107 | } | 
| 108 | 108 | |
| @@ -112,13 +112,13 @@ discard block | ||
| 112 | 112 | */ | 
| 113 | 113 | public function setMessageHandler($messageHandler, $uri = '*') | 
| 114 | 114 |      { | 
| 115 | -        if (!$messageHandler instanceof MessageHandlerInterface &&  !\is_string($messageHandler)) { | |
| 115 | +        if (!$messageHandler instanceof MessageHandlerInterface && !\is_string($messageHandler)) { | |
| 116 | 116 |              throw new \InvalidArgumentException('The message handler must be an instance of MessageHandlerInterface or a string.'); | 
| 117 | 117 | } | 
| 118 | 118 |          if (\is_string($messageHandler)) { | 
| 119 | 119 |              try { | 
| 120 | 120 | $reflection = new \ReflectionClass($messageHandler); | 
| 121 | -                if(!$reflection->implementsInterface('Nekland\Woketo\Message\MessageHandlerInterface')) { | |
| 121 | +                if (!$reflection->implementsInterface('Nekland\Woketo\Message\MessageHandlerInterface')) { | |
| 122 | 122 |                      throw new \InvalidArgumentException('The messageHandler must implement MessageHandlerInterface'); | 
| 123 | 123 | } | 
| 124 | 124 |              } catch (\ReflectionException $e) { | 
| @@ -150,7 +150,7 @@ discard block | ||
| 150 | 150 |              $this->getLogger()->info('Enabled ssl'); | 
| 151 | 151 | } | 
| 152 | 152 | |
| 153 | -        $this->server->on('connection', function (ConnectionInterface $socketStream) { | |
| 153 | +        $this->server->on('connection', function(ConnectionInterface $socketStream) { | |
| 154 | 154 | $this->onNewConnection($socketStream); | 
| 155 | 155 | }); | 
| 156 | 156 | |
| @@ -164,11 +164,11 @@ discard block | ||
| 164 | 164 | */ | 
| 165 | 165 | private function onNewConnection(ConnectionInterface $socketStream) | 
| 166 | 166 |      { | 
| 167 | -        $connection = new Connection($socketStream, function ($uri, Connection $connection) { | |
| 167 | +        $connection = new Connection($socketStream, function($uri, Connection $connection) { | |
| 168 | 168 | return $this->getMessageHandler($uri, $connection); | 
| 169 | 169 | }, $this->loop, $this->messageProcessor); | 
| 170 | 170 | |
| 171 | -        $socketStream->on('end', function () use($connection) { | |
| 171 | +        $socketStream->on('end', function() use($connection) { | |
| 172 | 172 | $this->onDisconnect($connection); | 
| 173 | 173 | }); | 
| 174 | 174 | |
| @@ -12,18 +12,18 @@ | ||
| 12 | 12 | namespace Nekland\Woketo\Client; | 
| 13 | 13 | |
| 14 | 14 | |
| 15 | -use Nekland\Woketo\Core\AbstractConnection; | |
| 16 | -use Nekland\Woketo\Exception\Http\IncompleteHttpMessageException; | |
| 17 | -use Nekland\Woketo\Exception\RuntimeException; | |
| 18 | -use Nekland\Woketo\Exception\WebsocketException; | |
| 19 | -use Nekland\Woketo\Http\Response; | |
| 20 | -use Nekland\Woketo\Http\Url; | |
| 21 | -use Nekland\Woketo\Message\MessageHandlerInterface; | |
| 22 | -use Nekland\Woketo\Rfc6455\Frame; | |
| 23 | -use Nekland\Woketo\Rfc6455\Handshake\ClientHandshake; | |
| 24 | -use Nekland\Woketo\Rfc6455\MessageProcessor; | |
| 25 | -use React\EventLoop\LoopInterface; | |
| 26 | -use React\Promise\PromiseInterface; | |
| 15 | +use Nekland\Woketo\Core\AbstractConnection; | |
| 16 | +use Nekland\Woketo\Exception\Http\IncompleteHttpMessageException; | |
| 17 | +use Nekland\Woketo\Exception\RuntimeException; | |
| 18 | +use Nekland\Woketo\Exception\WebsocketException; | |
| 19 | +use Nekland\Woketo\Http\Response; | |
| 20 | +use Nekland\Woketo\Http\Url; | |
| 21 | +use Nekland\Woketo\Message\MessageHandlerInterface; | |
| 22 | +use Nekland\Woketo\Rfc6455\Frame; | |
| 23 | +use Nekland\Woketo\Rfc6455\Handshake\ClientHandshake; | |
| 24 | +use Nekland\Woketo\Rfc6455\MessageProcessor; | |
| 25 | +use React\EventLoop\LoopInterface; | |
| 26 | +use React\Promise\PromiseInterface; | |
| 27 | 27 | use React\Socket\ConnectionInterface; | 
| 28 | 28 | |
| 29 | 29 | class Connection extends AbstractConnection | 
| @@ -52,17 +52,17 @@ discard block | ||
| 52 | 52 | $this->buffer = ''; | 
| 53 | 53 | $this->handler = $handler; | 
| 54 | 54 | |
| 55 | -        $clientPromise->then(function (ConnectionInterface $stream) {
 | |
| 55 | +        $clientPromise->then(function(ConnectionInterface $stream) {
 | |
| 56 | 56 | $this->stream = $stream; | 
| 57 | 57 | $this->onConnection($stream); | 
| 58 | -        }, function (\Exception $error) {
 | |
| 58 | +        }, function(\Exception $error) {
 | |
| 59 | 59 | $this->onError($error); | 
| 60 | 60 | }); | 
| 61 | 61 | } | 
| 62 | 62 | |
| 63 | 63 | private function onConnection(ConnectionInterface $stream) | 
| 64 | 64 |      {
 | 
| 65 | -        $stream->on('data', function (string $data) {
 | |
| 65 | +        $stream->on('data', function(string $data) {
 | |
| 66 | 66 | $this->onMessage($data); | 
| 67 | 67 | }); | 
| 68 | 68 | |
| @@ -123,7 +123,7 @@ discard block | ||
| 123 | 123 | |
| 124 | 124 |              if ($this->currentMessage->isComplete()) {
 | 
| 125 | 125 | // Sending the message through the woketo API. | 
| 126 | -                switch($this->currentMessage->getOpcode()) {
 | |
| 126 | +                switch ($this->currentMessage->getOpcode()) {
 | |
| 127 | 127 | case Frame::OP_TEXT: | 
| 128 | 128 | $this->getHandler()->onMessage($this->currentMessage->getContent(), $this); | 
| 129 | 129 | break; | 
| @@ -135,7 +135,7 @@ discard block | ||
| 135 | 135 | |
| 136 | 136 |              } else {
 | 
| 137 | 137 | // We wait for more data so we start a timeout. | 
| 138 | -                $this->timeout = $this->loop->addTimer(Connection::DEFAULT_TIMEOUT, function () {
 | |
| 138 | +                $this->timeout = $this->loop->addTimer(Connection::DEFAULT_TIMEOUT, function() {
 | |
| 139 | 139 |                      $this->getLogger()->notice('Connection to ' . $this->getIp() . ' timed out.');
 | 
| 140 | 140 | $this->messageProcessor->timeout($this->stream); | 
| 141 | 141 | }); | 
| @@ -27,11 +27,11 @@ discard block | ||
| 27 | 27 | */ | 
| 28 | 28 | class Frame | 
| 29 | 29 |  { | 
| 30 | - const OP_CONTINUE = 0; | |
| 31 | - const OP_TEXT = 1; | |
| 32 | - const OP_BINARY = 2; | |
| 33 | - const OP_CLOSE = 8; | |
| 34 | - const OP_PING = 9; | |
| 30 | + const OP_CONTINUE = 0; | |
| 31 | + const OP_TEXT = 1; | |
| 32 | + const OP_BINARY = 2; | |
| 33 | + const OP_CLOSE = 8; | |
| 34 | + const OP_PING = 9; | |
| 35 | 35 | const OP_PONG = 10; | 
| 36 | 36 | |
| 37 | 37 | // To understand codes, please refer to RFC: | 
| @@ -593,7 +593,7 @@ discard block | ||
| 593 | 593 |      { | 
| 594 | 594 | $this->config = \array_merge([ | 
| 595 | 595 | 'maxPayloadSize' => Frame::$defaultMaxPayloadSize, | 
| 596 | - ],$config); | |
| 596 | + ], $config); | |
| 597 | 597 | |
| 598 | 598 | return $this; | 
| 599 | 599 | } |