@@ -108,8 +108,7 @@ discard block  | 
                                                    ||
| 108 | 108 | */  | 
                                                        
| 109 | 109 | private function calculateAttemptsCount($seconds, $usec)  | 
                                                        
| 110 | 110 |      { | 
                                                        
| 111 | - $result = $seconds !== null ? ceil(($seconds * 1E6 + $usec) / self::ATTEMPT_DELAY) :  | 
                                                        |
| 112 | - self::ATTEMPT_COUNT_FOR_INFINITE_TIMEOUT;  | 
                                                        |
| 111 | + $result = $seconds !== null ? ceil(($seconds * 1E6 + $usec) / self::ATTEMPT_DELAY) : self::ATTEMPT_COUNT_FOR_INFINITE_TIMEOUT;  | 
                                                        |
| 113 | 112 |          if ($result < self::ATTEMPT_COUNT_FOR_INFINITE_TIMEOUT) { | 
                                                        
| 114 | 113 | $result = self::ATTEMPT_COUNT_FOR_INFINITE_TIMEOUT;  | 
                                                        
| 115 | 114 | }  | 
                                                        
@@ -328,8 +327,8 @@ discard block  | 
                                                    ||
| 328 | 327 | */  | 
                                                        
| 329 | 328 | public function removeAllSocketOperations(StreamResourceInterface $streamResource)  | 
                                                        
| 330 | 329 |      { | 
                                                        
| 331 | - $opList = [ OperationInterface::OPERATION_READ,  | 
                                                        |
| 332 | - OperationInterface::OPERATION_WRITE ];  | 
                                                        |
| 330 | + $opList = [OperationInterface::OPERATION_READ,  | 
                                                        |
| 331 | + OperationInterface::OPERATION_WRITE];  | 
                                                        |
| 333 | 332 | |
| 334 | 333 |          foreach ($opList as $op) { | 
                                                        
| 335 | 334 | $this->removeSocketOperation($streamResource, $op);  | 
                                                        
@@ -174,8 +174,7 @@ discard block  | 
                                                    ||
| 174 | 174 | '[#%s, %s]',  | 
                                                        
| 175 | 175 |                  preg_replace('/Resource id #(\d+)/i', '$1', (string) $this->resource), | 
                                                        
| 176 | 176 | $this->remoteAddress  | 
                                                        
| 177 | - ) :  | 
                                                        |
| 178 | - '[closed socket]';  | 
                                                        |
| 177 | + ) : '[closed socket]';  | 
                                                        |
| 179 | 178 | }  | 
                                                        
| 180 | 179 | |
| 181 | 180 | /**  | 
                                                        
@@ -218,7 +217,7 @@ discard block  | 
                                                    ||
| 218 | 217 | 'unix' => self::SOCKET_TYPE_UNIX,  | 
                                                        
| 219 | 218 | ];  | 
                                                        
| 220 | 219 | |
| 221 | -        $regexp = '#^('. implode('|', array_keys($map)) . ')_socket$#'; | 
                                                        |
| 220 | +        $regexp = '#^('.implode('|', array_keys($map)).')_socket$#'; | 
                                                        |
| 222 | 221 |          foreach ($parts as $part) { | 
                                                        
| 223 | 222 |              if (preg_match($regexp, $part, $pockets)) { | 
                                                        
| 224 | 223 | return $map[$pockets[1]];  | 
                                                        
@@ -121,7 +121,7 @@  | 
                                                    ||
| 121 | 121 | * @param string $needle What to find  | 
                                                        
| 122 | 122 | * @param int $offset Start offset in $haystack  | 
                                                        
| 123 | 123 | *  | 
                                                        
| 124 | - * @return bool|int  | 
                                                        |
| 124 | + * @return string  | 
                                                        |
| 125 | 125 | */  | 
                                                        
| 126 | 126 | protected function findMarker($haystack, $needle, $offset = 0)  | 
                                                        
| 127 | 127 |      { | 
                                                        
@@ -113,7 +113,7 @@ discard block  | 
                                                    ||
| 113 | 113 | $event = new ReadEvent(  | 
                                                        
| 114 | 114 | $executor,  | 
                                                        
| 115 | 115 | $socket,  | 
                                                        
| 116 | - $meta[ RequestExecutorInterface::META_USER_CONTEXT ],  | 
                                                        |
| 116 | + $meta[RequestExecutorInterface::META_USER_CONTEXT],  | 
                                                        |
| 117 | 117 | $frame,  | 
                                                        
| 118 | 118 | true  | 
                                                        
| 119 | 119 | );  | 
                                                        
@@ -140,8 +140,7 @@ discard block  | 
                                                    ||
| 140 | 140 |          if (!$counter) { | 
                                                        
| 141 | 141 | $meta = $descriptor->getMetadata();  | 
                                                        
| 142 | 142 | $counter = new SpeedRateCounter($minRate, $duration);  | 
                                                        
| 143 | - $time = $meta[RequestExecutorInterface::META_LAST_IO_START_TIME] ?:  | 
                                                        |
| 144 | - $meta[RequestExecutorInterface::META_CONNECTION_FINISH_TIME];  | 
                                                        |
| 143 | + $time = $meta[RequestExecutorInterface::META_LAST_IO_START_TIME] ?: $meta[RequestExecutorInterface::META_CONNECTION_FINISH_TIME];  | 
                                                        |
| 145 | 144 | $counter->advance($time, 0);  | 
                                                        
| 146 | 145 | $descriptor->registerCounter($name, $counter);  | 
                                                        
| 147 | 146 | }  | 
                                                        
@@ -204,26 +203,26 @@ discard block  | 
                                                    ||
| 204 | 203 | $map = [  | 
                                                        
| 205 | 204 | RequestDescriptor::COUNTER_RECV_MIN_RATE => [  | 
                                                        
| 206 | 205 | 'resetCounter' => RequestDescriptor::COUNTER_SEND_MIN_RATE,  | 
                                                        
| 207 | - 'minSpeed' => $meta[ RequestExecutorInterface::META_MIN_RECEIVE_SPEED ],  | 
                                                        |
| 208 | - 'duration' => $meta[ RequestExecutorInterface::META_MIN_RECEIVE_SPEED_DURATION ],  | 
                                                        |
| 206 | + 'minSpeed' => $meta[RequestExecutorInterface::META_MIN_RECEIVE_SPEED],  | 
                                                        |
| 207 | + 'duration' => $meta[RequestExecutorInterface::META_MIN_RECEIVE_SPEED_DURATION],  | 
                                                        |
| 209 | 208 | 'bytesCounter' => RequestExecutorInterface::META_BYTES_RECEIVED,  | 
                                                        
| 210 | 209 | 'speedCounter' => RequestExecutorInterface::META_RECEIVE_SPEED,  | 
                                                        
| 211 | - 'exception' => [ 'AsyncSockets\Exception\SlowSpeedTransferException', 'tooSlowDataReceiving' ],  | 
                                                        |
| 210 | + 'exception' => ['AsyncSockets\Exception\SlowSpeedTransferException', 'tooSlowDataReceiving'],  | 
                                                        |
| 212 | 211 | ],  | 
                                                        
| 213 | 212 | RequestDescriptor::COUNTER_SEND_MIN_RATE => [  | 
                                                        
| 214 | 213 | 'resetCounter' => RequestDescriptor::COUNTER_RECV_MIN_RATE,  | 
                                                        
| 215 | - 'minSpeed' => $meta[ RequestExecutorInterface::META_MIN_SEND_SPEED ],  | 
                                                        |
| 216 | - 'duration' => $meta[ RequestExecutorInterface::META_MIN_SEND_SPEED_DURATION ],  | 
                                                        |
| 214 | + 'minSpeed' => $meta[RequestExecutorInterface::META_MIN_SEND_SPEED],  | 
                                                        |
| 215 | + 'duration' => $meta[RequestExecutorInterface::META_MIN_SEND_SPEED_DURATION],  | 
                                                        |
| 217 | 216 | 'bytesCounter' => RequestExecutorInterface::META_BYTES_SENT,  | 
                                                        
| 218 | 217 | 'speedCounter' => RequestExecutorInterface::META_SEND_SPEED,  | 
                                                        
| 219 | - 'exception' => [ 'AsyncSockets\Exception\SlowSpeedTransferException', 'tooSlowDataSending' ],  | 
                                                        |
| 218 | + 'exception' => ['AsyncSockets\Exception\SlowSpeedTransferException', 'tooSlowDataSending'],  | 
                                                        |
| 220 | 219 | ],  | 
                                                        
| 221 | 220 | ];  | 
                                                        
| 222 | 221 | |
| 223 | -        if (!isset($map[ $name ])) { | 
                                                        |
| 224 | -            throw new \LogicException('Can not process counter ' . $name . ' in transfer operation'); | 
                                                        |
| 222 | +        if (!isset($map[$name])) { | 
                                                        |
| 223 | +            throw new \LogicException('Can not process counter '.$name.' in transfer operation'); | 
                                                        |
| 225 | 224 | }  | 
                                                        
| 226 | 225 | |
| 227 | - return $map[ $name ];  | 
                                                        |
| 226 | + return $map[$name];  | 
                                                        |
| 228 | 227 | }  | 
                                                        
| 229 | 228 | }  | 
                                                        
@@ -52,8 +52,7 @@ discard block  | 
                                                    ||
| 52 | 52 |          $this->verifySendResult('', stream_socket_sendto($resource, '')); | 
                                                        
| 53 | 53 | |
| 54 | 54 | $written = $isOutOfBand ?  | 
                                                        
| 55 | - $this->writeOobData($resource, $data) :  | 
                                                        |
| 56 | - fwrite($resource, $data, strlen($data));  | 
                                                        |
| 55 | + $this->writeOobData($resource, $data) : fwrite($resource, $data, strlen($data));  | 
                                                        |
| 57 | 56 | |
| 58 | 57 | $this->verifySendResult($data, $written);  | 
                                                        
| 59 | 58 | |
@@ -74,7 +73,7 @@ discard block  | 
                                                    ||
| 74 | 73 |          if ($sendResult === false || $sendResult < 0) { | 
                                                        
| 75 | 74 | throw new SendDataException(  | 
                                                        
| 76 | 75 | $this->socket,  | 
                                                        
| 77 | -                trim('Failed to send data. ' . $this->getLastPhpErrorMessage()) | 
                                                        |
| 76 | +                trim('Failed to send data. '.$this->getLastPhpErrorMessage()) | 
                                                        |
| 78 | 77 | );  | 
                                                        
| 79 | 78 | }  | 
                                                        
| 80 | 79 | |
@@ -148,7 +147,7 @@ discard block  | 
                                                    ||
| 148 | 147 |              if ($data === false) { | 
                                                        
| 149 | 148 | throw new RecvDataException(  | 
                                                        
| 150 | 149 | $this->socket,  | 
                                                        
| 151 | -                    trim('Failed to read data. ' . $this->getLastPhpErrorMessage()) | 
                                                        |
| 150 | +                    trim('Failed to read data. '.$this->getLastPhpErrorMessage()) | 
                                                        |
| 152 | 151 | );  | 
                                                        
| 153 | 152 | }  | 
                                                        
| 154 | 153 | |
@@ -202,9 +201,8 @@ discard block  | 
                                                    ||
| 202 | 201 | private function resolveReadAttempts(array $context, $currentAttempts)  | 
                                                        
| 203 | 202 |      { | 
                                                        
| 204 | 203 | return ($context['countCycles'] === 1 && empty($context['dataBeforeIo'])) ||  | 
                                                        
| 205 | - ($context['countCycles'] > 1 && $context['isStreamDataEmpty']) ?  | 
                                                        |
| 206 | - $currentAttempts - 1 :  | 
                                                        |
| 207 | - self::READ_ATTEMPTS;  | 
                                                        |
| 204 | + ($context['countCycles'] > 1 && $context['isStreamDataEmpty']) ?  | 
                                                        |
| 205 | + $currentAttempts - 1 : self::READ_ATTEMPTS;  | 
                                                        |
| 208 | 206 | |
| 209 | 207 | }  | 
                                                        
| 210 | 208 | |
@@ -95,11 +95,11 @@ discard block  | 
                                                    ||
| 95 | 95 |      { | 
                                                        
| 96 | 96 | $options += $this->getDefaultOptions();  | 
                                                        
| 97 | 97 | |
| 98 | - $this->connectTimeout = (double) $options[ 'connectTimeout' ];  | 
                                                        |
| 99 | - $this->ioTimeout = (double) $options[ 'ioTimeout' ];  | 
                                                        |
| 100 | - $this->preferredEngines = (array) $options[ 'preferredEngines' ];  | 
                                                        |
| 98 | + $this->connectTimeout = (double) $options['connectTimeout'];  | 
                                                        |
| 99 | + $this->ioTimeout = (double) $options['ioTimeout'];  | 
                                                        |
| 100 | + $this->preferredEngines = (array) $options['preferredEngines'];  | 
                                                        |
| 101 | 101 | |
| 102 | - $this->streamContext = new StreamContext($options[ 'streamContext' ]);  | 
                                                        |
| 102 | + $this->streamContext = new StreamContext($options['streamContext']);  | 
                                                        |
| 103 | 103 |          foreach (['minReceiveSpeed', 'minReceiveSpeedDuration', 'minSendSpeed', 'minSendSpeedDuration'] as $k) { | 
                                                        
| 104 | 104 |              $this->{$k} = $options[$k] !== null ? (int) $options[$k] : null; | 
                                                        
| 105 | 105 | }  | 
                                                        
@@ -195,14 +195,14 @@ discard block  | 
                                                    ||
| 195 | 195 | $result = [];  | 
                                                        
| 196 | 196 |          $socketTimeout = (double) ini_get('default_socket_timeout'); | 
                                                        
| 197 | 197 | |
| 198 | - $result[ 'connectTimeout' ] = $socketTimeout;  | 
                                                        |
| 199 | - $result[ 'ioTimeout' ] = $socketTimeout;  | 
                                                        |
| 200 | - $result[ 'preferredEngines' ] = [ 'libevent', 'native' ];  | 
                                                        |
| 201 | - $result[ 'streamContext' ] = null;  | 
                                                        |
| 202 | - $result[ 'minReceiveSpeed' ] = null;  | 
                                                        |
| 203 | - $result[ 'minReceiveSpeedDuration' ] = null;  | 
                                                        |
| 204 | - $result[ 'minSendSpeed' ] = null;  | 
                                                        |
| 205 | - $result[ 'minSendSpeedDuration' ] = null;  | 
                                                        |
| 198 | + $result['connectTimeout'] = $socketTimeout;  | 
                                                        |
| 199 | + $result['ioTimeout'] = $socketTimeout;  | 
                                                        |
| 200 | + $result['preferredEngines'] = ['libevent', 'native'];  | 
                                                        |
| 201 | + $result['streamContext'] = null;  | 
                                                        |
| 202 | + $result['minReceiveSpeed'] = null;  | 
                                                        |
| 203 | + $result['minReceiveSpeedDuration'] = null;  | 
                                                        |
| 204 | + $result['minSendSpeed'] = null;  | 
                                                        |
| 205 | + $result['minSendSpeedDuration'] = null;  | 
                                                        |
| 206 | 206 | |
| 207 | 207 | return $result;  | 
                                                        
| 208 | 208 | }  | 
                                                        
@@ -56,7 +56,7 @@ discard block  | 
                                                    ||
| 56 | 56 |              } elseif ($decision === LimitationSolverInterface::DECISION_SKIP_CURRENT) { | 
                                                        
| 57 | 57 | continue;  | 
                                                        
| 58 | 58 |              } elseif ($decision !== LimitationSolverInterface::DECISION_OK) { | 
                                                        
| 59 | -                throw new \LogicException('Unknown decision ' . $decision . ' received.'); | 
                                                        |
| 59 | +                throw new \LogicException('Unknown decision '.$decision.' received.'); | 
                                                        |
| 60 | 60 | }  | 
                                                        
| 61 | 61 | |
| 62 | 62 |              if ($this->connectSocket($descriptor)) { | 
                                                        
@@ -117,8 +117,8 @@ discard block  | 
                                                    ||
| 117 | 117 | $meta = $descriptor->getMetadata();  | 
                                                        
| 118 | 118 | |
| 119 | 119 | $socket->open(  | 
                                                        
| 120 | - $meta[ RequestExecutorInterface::META_ADDRESS ],  | 
                                                        |
| 121 | - $meta[ RequestExecutorInterface::META_SOCKET_STREAM_CONTEXT]  | 
                                                        |
| 120 | + $meta[RequestExecutorInterface::META_ADDRESS],  | 
                                                        |
| 121 | + $meta[RequestExecutorInterface::META_SOCKET_STREAM_CONTEXT]  | 
                                                        |
| 122 | 122 | );  | 
                                                        
| 123 | 123 | |
| 124 | 124 | $descriptor->setRunning(true);  | 
                                                        
@@ -178,7 +178,7 @@  | 
                                                    ||
| 178 | 178 | ];  | 
                                                        
| 179 | 179 | |
| 180 | 180 |          if (!is_array($key)) { | 
                                                        
| 181 | - $key = [ $key => $value ];  | 
                                                        |
| 181 | + $key = [$key => $value];  | 
                                                        |
| 182 | 182 | }  | 
                                                        
| 183 | 183 | |
| 184 | 184 | $key = array_intersect_key($key, $writableKeys);  | 
                                                        
@@ -56,9 +56,9 @@ discard block  | 
                                                    ||
| 56 | 56 | }  | 
                                                        
| 57 | 57 | |
| 58 | 58 | $map = [  | 
                                                        
| 59 | - 'null' => [ $this, 'createFromNull' ],  | 
                                                        |
| 60 | - 'resource' => [ $this, 'createFromResource' ],  | 
                                                        |
| 61 | - 'array' => [ $this, 'createFromArray' ],  | 
                                                        |
| 59 | + 'null' => [$this, 'createFromNull'],  | 
                                                        |
| 60 | + 'resource' => [$this, 'createFromResource'],  | 
                                                        |
| 61 | + 'array' => [$this, 'createFromArray'],  | 
                                                        |
| 62 | 62 | ];  | 
                                                        
| 63 | 63 | |
| 64 | 64 | $type = strtolower(gettype($settings));  | 
                                                        
@@ -107,8 +107,8 @@ discard block  | 
                                                    ||
| 107 | 107 | private function createFromArray(array $settings)  | 
                                                        
| 108 | 108 |      { | 
                                                        
| 109 | 109 | return stream_context_create(  | 
                                                        
| 110 | - isset($settings[ 'options' ]) ? $settings[ 'options' ] : [],  | 
                                                        |
| 111 | - isset($settings[ 'params' ]) ? $settings[ 'params' ] : []  | 
                                                        |
| 110 | + isset($settings['options']) ? $settings['options'] : [],  | 
                                                        |
| 111 | + isset($settings['params']) ? $settings['params'] : []  | 
                                                        |
| 112 | 112 | );  | 
                                                        
| 113 | 113 | }  | 
                                                        
| 114 | 114 | }  |