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 * 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 * The stream, where the current logger is writing into
* @var resource * @var resource|null
*/ */
private $stream; private $stream;
/** /**
* The current process ID * The current process ID
* @var int
*/ */
private $pid; private int $pid;
/** /**
* Translates LogLevel log levels to integer values * 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. * Translates LogLevel log levels to syslog log priorities.
* @var array * @var array<string,int>
*/ */
public const logLevels = [ public const logLevels = [
LogLevel::DEBUG => LOG_DEBUG, LogLevel::DEBUG => LOG_DEBUG,
@ -60,39 +60,33 @@ class SyslogLogger extends AbstractLogger
/** /**
* Indicates what logging options will be used when generating a log message * 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 * @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 * Used to specify what type of program is logging the message
* @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters * @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 * The minimum loglevel at which this logger will be triggered
* @var int
*/ */
private $logLevel; private int $logLevel;
/** /**
* A error message of the current operation * A error message of the current operation
* @var string
*/ */
private $errorMessage; private string $errorMessage;
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @param string $logLevel The minimum loglevel at which this logger will be triggered * @param int $logLevel The minimum loglevel at which this logger will be triggered
* @param string $logOptions * @param int $logOptions
* @param string $logFacility * @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); parent::__construct($channel, $introspection);
@ -166,7 +160,7 @@ class SyslogLogger extends AbstractLogger
restore_error_handler(); restore_error_handler();
if (!$opened) { 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); $this->syslogWrapper($priority, $message);
@ -215,7 +209,7 @@ class SyslogLogger extends AbstractLogger
restore_error_handler(); restore_error_handler();
if (!$written) { 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 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 public function create(IManageConfigValues $config): LoggerInterface
{ {
$logOpts = $config->get('system', 'syslog_flags') ?? SyslogLoggerClass::DEFAULT_FLAGS; $logOpts = (int) $config->get('system', 'syslog_flags') ?? SyslogLoggerClass::DEFAULT_FLAGS;
$logFacility = $config->get('system', 'syslog_facility') ?? SyslogLoggerClass::DEFAULT_FACILITY; $logFacility = (int) $config->get('system', 'syslog_facility') ?? SyslogLoggerClass::DEFAULT_FACILITY;
$loglevel = SyslogLogger::mapLegacyConfigDebugLevel($config->get('system', 'loglevel')); $loglevel = SyslogLogger::mapLegacyConfigDebugLevel($config->get('system', 'loglevel'));
if (array_key_exists($loglevel, SyslogLoggerClass::logLevels)) { if (!array_key_exists($loglevel, SyslogLoggerClass::logLevels)) {
$loglevel = SyslogLoggerClass::logLevels[$loglevel];
} else {
throw new LogLevelException(sprintf('The level "%s" is not valid.', $loglevel)); 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); return new SyslogLoggerWrapper($this->channel, $this->introspection, $loglevel, $logOpts, $logFacility);
} }
} }

View file

@ -17,7 +17,7 @@ class SyslogLoggerWrapper extends SyslogLogger
{ {
private $content; 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); parent::__construct($channel, $introspection, $logLevel, $logOptions, $logFacility);