Skip to content

Commit

Permalink
Added ignore lines
Browse files Browse the repository at this point in the history
  • Loading branch information
vladvildanov committed Apr 10, 2024
1 parent fc96247 commit 02be8f5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/Connection/AbstractConnection.php
Expand Up @@ -19,7 +19,6 @@
use Predis\Protocol\Parser\ParserStrategyResolver;
use Predis\Protocol\Parser\Strategy\ParserStrategyInterface;
use Predis\Protocol\ProtocolException;
use Psr\Http\Message\StreamInterface;

/**
* Base class with the common logic used by connection classes to communicate
Expand Down Expand Up @@ -148,10 +147,11 @@ public function readResponse(CommandInterface $command)
/**
* Helper method to handle connection errors.
*
* @param string $message Error message.
* @param int $code Error code.
* @param string $message Error message.
* @param int $code Error code.
* @throws CommunicationException
*/
protected function onConnectionError($message, $code = 0)
protected function onConnectionError($message, $code = 0): void
{
CommunicationException::handle(
new ConnectionException($this, "$message [{$this->getParameters()}]", $code)
Expand All @@ -161,7 +161,7 @@ protected function onConnectionError($message, $code = 0)
/**
* Helper method to handle protocol errors.
*
* @param string $message Error message.
* @param string $message Error message.
* @throws CommunicationException
*/
protected function onProtocolError($message)
Expand Down
6 changes: 3 additions & 3 deletions src/Connection/CompositeStreamConnection.php
Expand Up @@ -80,8 +80,8 @@ public function readBuffer($length)
$this->onStreamError($e, 'Error while reading bytes from the server.');
}

$value .= $chunk;
} while (($length -= strlen($chunk)) > 0);
$value .= $chunk; // @phpstan-ignore-line
} while (($length -= strlen($chunk)) > 0); // @phpstan-ignore-line

return $value;
}
Expand All @@ -105,7 +105,7 @@ public function readLine()
$this->onStreamError($e, 'Error while reading bytes from the server.');
}

$value .= $chunk;
$value .= $chunk; // @phpstan-ignore-line
} while (substr($value, -2) !== "\r\n");

return substr($value, 0, -2);
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/Resource/Stream.php
Expand Up @@ -232,7 +232,7 @@ public function isReadable(): bool

/**
* {@inheritDoc}
* @param int $length If length = -1, reads a stream line by line (e.g fgets())
* @param int $length If length = -1, reads a stream line by line (e.g fgets())
* @throws RuntimeException
*/
public function read(int $length): string
Expand Down
29 changes: 16 additions & 13 deletions src/Connection/StreamConnection.php
Expand Up @@ -113,6 +113,7 @@ public function disconnect()

/**
* {@inheritDoc}
* @throws CommunicationException
*/
public function write(string $buffer): void
{
Expand All @@ -125,11 +126,11 @@ public function write(string $buffer): void
$this->onStreamError($e, 'Error while writing bytes to the server.');
}

if ($length === $written) {
if ($length === $written) { // @phpstan-ignore-line
return;
}

$buffer = substr($buffer, $written);
$buffer = substr($buffer, $written); // @phpstan-ignore-line
}
}

Expand All @@ -153,7 +154,7 @@ public function read()
}

try {
$parsedData = $this->parserStrategy->parseData($chunk);
$parsedData = $this->parserStrategy->parseData($chunk); // @phpstan-ignore-line
} catch (UnexpectedTypeException $e) {
$this->onProtocolError("Unknown response prefix: '{$e->getType()}'.");

Expand Down Expand Up @@ -244,9 +245,10 @@ public function hasDataToRead(): bool
/**
* Reads given resource split on chunks with given size.
*
* @param StreamInterface $stream
* @param int $chunkSize
* @param StreamInterface $stream
* @param int $chunkSize
* @return string
* @throws CommunicationException
*/
private function readByChunks(StreamInterface $stream, int $chunkSize): string
{
Expand All @@ -260,7 +262,7 @@ private function readByChunks(StreamInterface $stream, int $chunkSize): string
$this->onStreamError($e, 'Error while reading bytes from the server.');
}

$string .= $chunk;
$string .= $chunk; // @phpstan-ignore-line
$bytesLeft = $chunkSize - strlen($string);
} while ($bytesLeft > 0);

Expand All @@ -270,9 +272,10 @@ private function readByChunks(StreamInterface $stream, int $chunkSize): string
/**
* Handle response from on-connect command.
*
* @param $response
* @param CommandInterface $command
* @param $response
* @param CommandInterface $command
* @return void
* @throws CommunicationException
*/
private function handleOnConnectResponse($response, CommandInterface $command): void
{
Expand All @@ -299,6 +302,7 @@ private function handleOnConnectResponse($response, CommandInterface $command):
* @param ErrorResponseInterface $error
* @param CommandInterface $failedCommand
* @return void
* @throws CommunicationException
*/
private function handleError(ErrorResponseInterface $error, CommandInterface $failedCommand): void
{
Expand Down Expand Up @@ -329,12 +333,11 @@ private function handleError(ErrorResponseInterface $error, CommandInterface $fa
/**
* Handles stream-related exceptions.
*
* @param RuntimeException $e
* @param string|null $message
* @return void
* @throws RuntimeException
* @param RuntimeException $e
* @param string|null $message
* @throws RuntimeException|CommunicationException
*/
protected function onStreamError(RuntimeException $e, ?string $message = null): void
protected function onStreamError(RuntimeException $e, ?string $message = null)
{
// Code = 1 represents issues related to read/write operation.
if ($e->getCode() === 1) {
Expand Down

0 comments on commit 02be8f5

Please sign in to comment.