From a63babc658fe7a609474fb9328419c3a2e380f76 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 13 Mar 2025 12:20:43 +0000 Subject: [PATCH] Fix 6 PHPStan errors --- src/Core/Logger/Type/StreamLogger.php | 8 ++---- src/Core/Logger/Type/SyslogLogger.php | 28 ++++++++----------- src/Core/PConfig/Repository/PConfig.php | 2 +- .../Logger/SyslogLoggerFactoryWrapper.php | 10 +++---- tests/src/Core/Logger/SyslogLoggerWrapper.php | 2 +- 5 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/Core/Logger/Type/StreamLogger.php b/src/Core/Logger/Type/StreamLogger.php index 81af7e4474..03dfe69b6d 100644 --- a/src/Core/Logger/Type/StreamLogger.php +++ b/src/Core/Logger/Type/StreamLogger.php @@ -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 diff --git a/src/Core/Logger/Type/SyslogLogger.php b/src/Core/Logger/Type/SyslogLogger.php index 8f24af053c..8b5f34634f 100644 --- a/src/Core/Logger/Type/SyslogLogger.php +++ b/src/Core/Logger/Type/SyslogLogger.php @@ -29,7 +29,7 @@ class SyslogLogger extends AbstractLogger /** * Translates LogLevel log levels to syslog log priorities. - * @var array + * @var array */ 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)); } } } diff --git a/src/Core/PConfig/Repository/PConfig.php b/src/Core/PConfig/Repository/PConfig.php index d3b68b8ce1..af59e23fc3 100644 --- a/src/Core/PConfig/Repository/PConfig.php +++ b/src/Core/PConfig/Repository/PConfig.php @@ -37,7 +37,7 @@ class PConfig */ public function isConnected(): bool { - return $this->db->isConnected() & !$this->mode->isInstall(); + return $this->db->isConnected() && !$this->mode->isInstall(); } /** diff --git a/tests/src/Core/Logger/SyslogLoggerFactoryWrapper.php b/tests/src/Core/Logger/SyslogLoggerFactoryWrapper.php index 10b19d1991..6bc30bc439 100644 --- a/tests/src/Core/Logger/SyslogLoggerFactoryWrapper.php +++ b/tests/src/Core/Logger/SyslogLoggerFactoryWrapper.php @@ -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); } } diff --git a/tests/src/Core/Logger/SyslogLoggerWrapper.php b/tests/src/Core/Logger/SyslogLoggerWrapper.php index e0e360a50f..df2944c4c5 100644 --- a/tests/src/Core/Logger/SyslogLoggerWrapper.php +++ b/tests/src/Core/Logger/SyslogLoggerWrapper.php @@ -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);