Skip to content

Commit

Permalink
fix: static analysis warnings (php-amqplib#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramunasd authored Jan 25, 2024
1 parent 7b53af7 commit 109b13d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
14 changes: 5 additions & 9 deletions PhpAmqpLib/Wire/IO/AbstractIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class AbstractIO
/** @var int|float */
protected $last_write;

/** @var array|null */
/** @var array<string, mixed>|null */
protected $last_error;

/** @var bool */
Expand Down Expand Up @@ -159,7 +159,7 @@ public function check_heartbeat()
/**
* @throws \PhpAmqpLib\Exception\AMQPHeartbeatMissedException
*/
protected function checkBrokerHeartbeat()
protected function checkBrokerHeartbeat(): void
{
if ($this->heartbeat > 0 && ($this->last_read > 0 || $this->last_write > 0)) {
$lastActivity = $this->getLastActivity();
Expand Down Expand Up @@ -252,20 +252,16 @@ protected function restoreErrorHandler(): void
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param array $errcontext
* @return void
*/
public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = null)
public function error_handler($errno, $errstr, $errfile, $errline): void
{
// throwing an exception in an error handler will halt execution
// set the last error and continue
$this->last_error = compact('errno', 'errstr', 'errfile', 'errline', 'errcontext');
$this->last_error = compact('errno', 'errstr', 'errfile', 'errline');
}

/**
* @return bool
*/
protected function isPcntlSignalEnabled()
protected function isPcntlSignalEnabled(): bool
{
return extension_loaded('pcntl')
&& function_exists('pcntl_signal_dispatch')
Expand Down
13 changes: 7 additions & 6 deletions PhpAmqpLib/Wire/IO/SocketIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class SocketIO extends AbstractIO
{
/** @var null|resource */
/** @var null|resource|\Socket */
private $sock;

/**
Expand Down Expand Up @@ -100,7 +100,8 @@ public function connect()
}

/**
* @inheritdoc
* @deprecated
* @return null|resource|\Socket
*/
public function getSocket()
{
Expand Down Expand Up @@ -280,7 +281,7 @@ protected function select_write()
/**
* @throws \PhpAmqpLib\Exception\AMQPIOException
*/
protected function enable_keepalive()
protected function enable_keepalive(): void
{
if (!defined('SOL_SOCKET') || !defined('SO_KEEPALIVE')) {
throw new AMQPIOException('Can not enable keepalive: SOL_SOCKET or SO_KEEPALIVE is not defined');
Expand All @@ -292,7 +293,7 @@ protected function enable_keepalive()
/**
* @inheritdoc
*/
public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = null)
public function error_handler($errno, $errstr, $errfile, $errline): void
{
$constants = SocketConstants::getInstance();
// socket_select warning that it has been interrupted by a signal - EINTR
Expand All @@ -301,7 +302,7 @@ public function error_handler($errno, $errstr, $errfile, $errline, $errcontext =
return;
}

parent::error_handler($errno, $errstr, $errfile, $errline, $errcontext);
parent::error_handler($errno, $errstr, $errfile, $errline);
}

/**
Expand All @@ -313,7 +314,7 @@ protected function setErrorHandler(): void
socket_clear_error($this->sock);
}

private function isIpv6(): string
private function isIpv6(): bool
{
$ipv6 = filter_var($this->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);

Expand Down
13 changes: 7 additions & 6 deletions PhpAmqpLib/Wire/IO/StreamIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class StreamIO extends AbstractIO
* @param int $port
* @param float $connection_timeout
* @param float $read_write_timeout
* @param resource|array|null $context
* @param resource|null $context
* @param bool $keepalive
* @param int $heartbeat
* @param string|null $ssl_protocol @deprecated
Expand Down Expand Up @@ -124,7 +124,7 @@ public function connect()

// php cannot capture signals while streams are blocking
if ($this->canDispatchPcntlSignal) {
stream_set_blocking($this->sock, 0);
stream_set_blocking($this->sock, false);
stream_set_write_buffer($this->sock, 0);
if (function_exists('stream_set_read_buffer')) {
stream_set_read_buffer($this->sock, 0);
Expand Down Expand Up @@ -316,7 +316,7 @@ public function write($data)
/**
* @inheritdoc
*/
public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = null)
public function error_handler($errno, $errstr, $errfile, $errline): void
{
$code = $this->extract_error_code($errstr);
$constants = SocketConstants::getInstance();
Expand All @@ -329,7 +329,7 @@ public function error_handler($errno, $errstr, $errfile, $errline, $errcontext =
return;
}

parent::error_handler($code > 0 ? $code : $errno, $errstr, $errfile, $errline, $errcontext);
parent::error_handler($code > 0 ? $code : $errno, $errstr, $errfile, $errline);
}

public function close()
Expand All @@ -344,7 +344,8 @@ public function close()
}

/**
* @inheritdoc
* @deprecated
* @return null|resource|\Socket
*/
public function getSocket()
{
Expand Down Expand Up @@ -397,7 +398,7 @@ protected function timed_out()
/**
* @throws \PhpAmqpLib\Exception\AMQPIOException
*/
protected function enable_keepalive()
protected function enable_keepalive(): void
{
if (!function_exists('socket_import_stream')) {
throw new AMQPIOException('Can not enable keepalive: function socket_import_stream does not exist');
Expand Down

0 comments on commit 109b13d

Please sign in to comment.