Fix 6 PHPStan errors

This commit is contained in:
Art4 2025-03-13 12:20:43 +00:00
parent 441846cfbd
commit a63babc658
5 changed files with 21 additions and 29 deletions

View file

@ -22,21 +22,19 @@ class StreamLogger extends AbstractLogger
/**
* The minimum loglevel at which this logger will be triggered
* @var string
*/
private $logLevel;
private int $logLevel;
/**
* The stream, where the current logger is writing into
* @var resource
* @var resource|null
*/
private $stream;
/**
* The current process ID
* @var int
*/
private $pid;
private int $pid;
/**
* Translates LogLevel log levels to integer values

View file

@ -29,7 +29,7 @@ class SyslogLogger extends AbstractLogger
/**
* Translates LogLevel log levels to syslog log priorities.
* @var array
* @var array<string,int>
*/
public const logLevels = [
LogLevel::DEBUG => LOG_DEBUG,
@ -60,39 +60,33 @@ class SyslogLogger extends AbstractLogger
/**
* Indicates what logging options will be used when generating a log message
* @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters
*
* @var int
*/
private $logOpts;
private int $logOpts;
/**
* Used to specify what type of program is logging the message
* @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters
*
* @var int
*/
private $logFacility;
private int $logFacility;
/**
* The minimum loglevel at which this logger will be triggered
* @var int
*/
private $logLevel;
private int $logLevel;
/**
* A error message of the current operation
* @var string
*/
private $errorMessage;
private string $errorMessage;
/**
* {@inheritdoc}
*
* @param string $logLevel The minimum loglevel at which this logger will be triggered
* @param string $logOptions
* @param string $logFacility
* @param int $logLevel The minimum loglevel at which this logger will be triggered
* @param int $logOptions
* @param int $logFacility
*/
public function __construct(string $channel, IHaveCallIntrospections $introspection, string $logLevel, string $logOptions, string $logFacility)
public function __construct(string $channel, IHaveCallIntrospections $introspection, int $logLevel, int $logOptions, int $logFacility)
{
parent::__construct($channel, $introspection);
@ -166,7 +160,7 @@ class SyslogLogger extends AbstractLogger
restore_error_handler();
if (!$opened) {
throw new LoggerException(sprintf('Can\'t open syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, $this->logFacility));
throw new LoggerException(sprintf('Can\'t open syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, (string) $this->logFacility));
}
$this->syslogWrapper($priority, $message);
@ -215,7 +209,7 @@ class SyslogLogger extends AbstractLogger
restore_error_handler();
if (!$written) {
throw new LoggerException(sprintf('Can\'t write into syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, $this->logFacility));
throw new LoggerException(sprintf('Can\'t write into syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, (string) $this->logFacility));
}
}
}

View file

@ -37,7 +37,7 @@ class PConfig
*/
public function isConnected(): bool
{
return $this->db->isConnected() & !$this->mode->isInstall();
return $this->db->isConnected() && !$this->mode->isInstall();
}
/**

View file

@ -17,16 +17,16 @@ class SyslogLoggerFactoryWrapper extends SyslogLogger
{
public function create(IManageConfigValues $config): LoggerInterface
{
$logOpts = $config->get('system', 'syslog_flags') ?? SyslogLoggerClass::DEFAULT_FLAGS;
$logFacility = $config->get('system', 'syslog_facility') ?? SyslogLoggerClass::DEFAULT_FACILITY;
$logOpts = (int) $config->get('system', 'syslog_flags') ?? SyslogLoggerClass::DEFAULT_FLAGS;
$logFacility = (int) $config->get('system', 'syslog_facility') ?? SyslogLoggerClass::DEFAULT_FACILITY;
$loglevel = SyslogLogger::mapLegacyConfigDebugLevel($config->get('system', 'loglevel'));
if (array_key_exists($loglevel, SyslogLoggerClass::logLevels)) {
$loglevel = SyslogLoggerClass::logLevels[$loglevel];
} else {
if (!array_key_exists($loglevel, SyslogLoggerClass::logLevels)) {
throw new LogLevelException(sprintf('The level "%s" is not valid.', $loglevel));
}
$loglevel = SyslogLoggerClass::logLevels[$loglevel];
return new SyslogLoggerWrapper($this->channel, $this->introspection, $loglevel, $logOpts, $logFacility);
}
}

View file

@ -17,7 +17,7 @@ class SyslogLoggerWrapper extends SyslogLogger
{
private $content;
public function __construct(string $channel, IHaveCallIntrospections $introspection, string $logLevel, string $logOptions, string $logFacility)
public function __construct(string $channel, IHaveCallIntrospections $introspection, int $logLevel, int $logOptions, int $logFacility)
{
parent::__construct($channel, $introspection, $logLevel, $logOptions, $logFacility);