]> git.mxchange.org Git - friendica.git/commitdiff
Fix 6 PHPStan errors
authorArt4 <art4@wlabs.de>
Thu, 13 Mar 2025 12:20:43 +0000 (12:20 +0000)
committerArt4 <art4@wlabs.de>
Thu, 13 Mar 2025 12:20:43 +0000 (12:20 +0000)
src/Core/Logger/Type/StreamLogger.php
src/Core/Logger/Type/SyslogLogger.php
src/Core/PConfig/Repository/PConfig.php
tests/src/Core/Logger/SyslogLoggerFactoryWrapper.php
tests/src/Core/Logger/SyslogLoggerWrapper.php

index 81af7e447468089b43d57e60726f7294fd73070d..03dfe69b6d449b3d314daeb26aaea73833cab12f 100644 (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
index 8f24af053c97be18c0d85bda462b7cf52b36c45e..8b5f34634f7d42e5aeb7798cd4b75f7d867980fd 100644 (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));
                }
        }
 }
index d3b68b8ce1135c74a954971d927afd8f28c57989..af59e23fc318800f6f638e0b80cd0db88d3b2d17 100644 (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();
        }
 
        /**
index 10b19d1991b924c2d508a191dca9046a7b121bf3..6bc30bc4396f9b00e17c60f0876fd93fbca06b9b 100644 (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);
        }
 }
index e0e360a50fcc17c90423464b29955867e0755209..df2944c4c521802edea305bb2e2d8710d334e30d 100644 (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);