From 496f0755b1f8f7d1c89be1a0700ebc9fa290e2c5 Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 3 Dec 2024 20:11:46 +0000 Subject: [PATCH] Fix errors in Core namespace --- .../Text/HTMLPurifier_URIScheme_cid.php | 5 +- src/Core/ACL.php | 1 + src/Core/Cache/Capability/ICanCache.php | 2 +- src/Core/Config/Model/ConfigTransaction.php | 3 +- src/Core/L10n.php | 6 +- src/Core/Lock/Capability/ICanLock.php | 2 +- src/Core/Lock/Type/CacheLock.php | 6 +- src/Core/Logger.php | 14 ++-- src/Core/Logger/Type/StreamLogger.php | 2 +- src/Core/Logger/Util/LoggerSettingsCheck.php | 16 ++-- .../Storage/Repository/StorageManager.php | 77 ++++++++++--------- src/Core/System.php | 8 +- src/Core/Worker.php | 8 +- src/Core/Worker/Repository/Process.php | 2 +- src/DI.php | 2 +- 15 files changed, 79 insertions(+), 75 deletions(-) diff --git a/src/Content/Text/HTMLPurifier_URIScheme_cid.php b/src/Content/Text/HTMLPurifier_URIScheme_cid.php index 8ed03f7c5d..05d7e27722 100644 --- a/src/Content/Text/HTMLPurifier_URIScheme_cid.php +++ b/src/Content/Text/HTMLPurifier_URIScheme_cid.php @@ -7,7 +7,10 @@ namespace Friendica\Content\Text; -use \HTMLPurifier_URIScheme; +use HTMLPurifier_Config; +use HTMLPurifier_Context; +use HTMLPurifier_URI; +use HTMLPurifier_URIScheme; /** * Validates content-id ("cid") as used in multi-part MIME messages, as defined by RFC 2392 diff --git a/src/Core/ACL.php b/src/Core/ACL.php index bfd751c086..e0ff7e9e6a 100644 --- a/src/Core/ACL.php +++ b/src/Core/ACL.php @@ -7,6 +7,7 @@ namespace Friendica\Core; +use Exception; use Friendica\App\Page; use Friendica\Database\DBA; use Friendica\DI; diff --git a/src/Core/Cache/Capability/ICanCache.php b/src/Core/Cache/Capability/ICanCache.php index 6360342c5e..0b7dc647c3 100644 --- a/src/Core/Cache/Capability/ICanCache.php +++ b/src/Core/Cache/Capability/ICanCache.php @@ -18,7 +18,7 @@ interface ICanCache /** * Lists all cache keys * - * @param string|null prefix optional a prefix to search + * @param string|null $prefix optional a prefix to search * * @return array Empty if it isn't supported by the cache driver */ diff --git a/src/Core/Config/Model/ConfigTransaction.php b/src/Core/Config/Model/ConfigTransaction.php index f832d93e0c..c3703364a8 100644 --- a/src/Core/Config/Model/ConfigTransaction.php +++ b/src/Core/Config/Model/ConfigTransaction.php @@ -7,7 +7,6 @@ namespace Friendica\Core\Config\Model; -use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally; use Friendica\Core\Config\Exception\ConfigPersistenceException; use Friendica\Core\Config\ValueObject\Cache; @@ -17,7 +16,7 @@ use Friendica\Core\Config\ValueObject\Cache; */ class ConfigTransaction implements ISetConfigValuesTransactionally { - /** @var IManageConfigValues */ + /** @var DatabaseConfig */ protected $config; /** @var Cache */ protected $setCache; diff --git a/src/Core/L10n.php b/src/Core/L10n.php index fd70063fb6..79d83950a9 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -345,10 +345,6 @@ class L10n /** * Provide a fallback which will not collide with a function defined in any language file - * - * @param int $n - * - * @return bool */ private function stringPluralSelectDefault(float $n): bool { @@ -426,7 +422,7 @@ class L10n $iso639 = new \Matriphe\ISO639\ISO639; // In ISO 639-2 undetermined languages have got the code "und". - // There is no official code for ISO 639-1, but "un" is not assigned to any language. + // There is no official code for ISO 639-1, but "un" is not assigned to any language. $languages = [self::UNDETERMINED_LANGUAGE => $this->t('Undetermined')]; foreach ($this->getDetectableLanguages() as $code) { diff --git a/src/Core/Lock/Capability/ICanLock.php b/src/Core/Lock/Capability/ICanLock.php index ef7dfcae77..ae15a751ac 100644 --- a/src/Core/Lock/Capability/ICanLock.php +++ b/src/Core/Lock/Capability/ICanLock.php @@ -65,7 +65,7 @@ interface ICanLock /** * Lists all locks * - * @param string prefix optional a prefix to search + * @param string $prefix optional a prefix to search * * @return string[] Empty if it isn't supported by the cache driver * diff --git a/src/Core/Lock/Type/CacheLock.php b/src/Core/Lock/Type/CacheLock.php index 65b07b9bfd..c3794d06a7 100644 --- a/src/Core/Lock/Type/CacheLock.php +++ b/src/Core/Lock/Type/CacheLock.php @@ -16,12 +16,14 @@ use Friendica\Core\Lock\Exception\LockPersistenceException; class CacheLock extends AbstractLock { /** - * @var string The static prefix of all locks inside the cache + * The static prefix of all locks inside the cache + * + * @var string */ const CACHE_PREFIX = 'lock:'; /** - * @var ICanCache; + * @var ICanCacheInMemory */ private $cache; diff --git a/src/Core/Logger.php b/src/Core/Logger.php index ee6e3df86f..48fd1293b3 100644 --- a/src/Core/Logger.php +++ b/src/Core/Logger.php @@ -18,20 +18,24 @@ use Psr\Log\LogLevel; class Logger { /** - * @var LoggerInterface The default Logger type + * LoggerInterface The default Logger type + * + * @var string */ const TYPE_LOGGER = LoggerInterface::class; /** - * @var WorkerLogger A specific worker logger type, which can be enabled + * WorkerLogger A specific worker logger type, which can be enabled + * + * @var string */ const TYPE_WORKER = WorkerLogger::class; /** - * @var LoggerInterface The current logger type + * @var string $type LoggerInterface The current logger type */ private static $type = self::TYPE_LOGGER; /** - * @return LoggerInterface + * @return LoggerInterface|WorkerLogger */ private static function getInstance() { @@ -52,7 +56,7 @@ class Logger public static function enableWorker(string $functionName) { self::$type = self::TYPE_WORKER; - self::getInstance()->setFunctionName($functionName); + DI::workerLogger()->setFunctionName($functionName); } /** diff --git a/src/Core/Logger/Type/StreamLogger.php b/src/Core/Logger/Type/StreamLogger.php index 670181c33a..81af7e4474 100644 --- a/src/Core/Logger/Type/StreamLogger.php +++ b/src/Core/Logger/Type/StreamLogger.php @@ -55,7 +55,7 @@ class StreamLogger extends AbstractLogger /** * {@inheritdoc} - * @param string $level The minimum loglevel at which this logger will be triggered + * @param int $logLevel The minimum loglevel at which this logger will be triggered * * @throws LoggerException */ diff --git a/src/Core/Logger/Util/LoggerSettingsCheck.php b/src/Core/Logger/Util/LoggerSettingsCheck.php index a62254c048..835ba0e610 100644 --- a/src/Core/Logger/Util/LoggerSettingsCheck.php +++ b/src/Core/Logger/Util/LoggerSettingsCheck.php @@ -17,7 +17,7 @@ class LoggerSettingsCheck implements ICheckLoggerSettings { /** @var IManageConfigValues */ protected $config; - /** @var $fileSystem */ + /** @var FileSystem */ protected $fileSystem; /** @var L10n */ protected $l10n; @@ -38,10 +38,8 @@ class LoggerSettingsCheck implements ICheckLoggerSettings try { $stream = $this->fileSystem->createStream($file); - - if (!isset($stream)) { - throw new LoggerUnusableException('Stream is null.'); - } + } catch (LoggerUnusableException $exception) { + throw new LoggerUnusableException('Stream is null.', $exception); } catch (\Throwable $exception) { return $this->l10n->t('The logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage()); } @@ -57,16 +55,14 @@ class LoggerSettingsCheck implements ICheckLoggerSettings if ($this->config->get('system', 'debugging')) { $file = $this->config->get('system', 'dlogfile'); - if (empty($file)) { + if ($file === null || $file === '') { return null; } try { $stream = $this->fileSystem->createStream($file); - - if (!isset($stream)) { - throw new LoggerUnusableException('Stream is null.'); - } + } catch (LoggerUnusableException $exception) { + throw new LoggerUnusableException('Stream is null.', $exception); } catch (\Throwable $exception) { return $this->l10n->t('The debug logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage()); } diff --git a/src/Core/Storage/Repository/StorageManager.php b/src/Core/Storage/Repository/StorageManager.php index 3ab2022059..47b3bcca55 100644 --- a/src/Core/Storage/Repository/StorageManager.php +++ b/src/Core/Storage/Repository/StorageManager.php @@ -274,24 +274,24 @@ class StorageManager */ public function register(string $class): bool { - if (is_subclass_of($class, ICanReadFromStorage::class)) { - /** @var ICanReadFromStorage $class */ - if ($this->isValidBackend($class::getName(), $this->validBackends)) { - return true; - } - - $backends = $this->validBackends; - $backends[] = $class::getName(); - - if ($this->config->set('storage', 'backends', $backends)) { - $this->validBackends = $backends; - return true; - } else { - return false; - } - } else { + if (!is_subclass_of($class, ICanReadFromStorage::class)) { return false; } + + /** @var class-string $class */ + if ($this->isValidBackend($class::getName(), $this->validBackends)) { + return true; + } + + $backends = $this->validBackends; + $backends[] = $class::getName(); + + if ($this->config->set('storage', 'backends', $backends)) { + $this->validBackends = $backends; + return true; + } + + return false; } /** @@ -305,30 +305,31 @@ class StorageManager */ public function unregister(string $class): bool { - if (is_subclass_of($class, ICanReadFromStorage::class)) { - /** @var ICanReadFromStorage $class */ - if ($this->currentBackend::getName() == $class::getName()) { - throw new StorageException(sprintf('Cannot unregister %s, because it\'s currently active.', $class::getName())); - } - - $key = array_search($class::getName(), $this->validBackends); - - if ($key !== false) { - $backends = $this->validBackends; - unset($backends[$key]); - $backends = array_values($backends); - if ($this->config->set('storage', 'backends', $backends)) { - $this->validBackends = $backends; - return true; - } else { - return false; - } - } else { - return true; - } - } else { + if (!is_subclass_of($class, ICanReadFromStorage::class)) { return false; } + + /** @var class-string $class */ + if ($this->currentBackend::getName() == $class::getName()) { + throw new StorageException(sprintf('Cannot unregister %s, because it\'s currently active.', $class::getName())); + } + + $key = array_search($class::getName(), $this->validBackends); + + if ($key === false) { + return true; + } + + $backends = $this->validBackends; + unset($backends[$key]); + $backends = array_values($backends); + + if ($this->config->set('storage', 'backends', $backends)) { + $this->validBackends = $backends; + return true; + } + + return false; } /** diff --git a/src/Core/System.php b/src/Core/System.php index 3eabf9695d..95a411f3d1 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -8,10 +8,8 @@ namespace Friendica\Core; use Friendica\Content\Text\BBCode; -use Friendica\Content\Text\HTML; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\DI; -use Friendica\Model\User; use Friendica\Module\Response; use Friendica\Network\HTTPException\FoundException; use Friendica\Network\HTTPException\InternalServerErrorException; @@ -325,9 +323,9 @@ class System /** * Send HTTP status header and exit. * - * @param integer $val HTTP status result value - * @param string $message Error message. Optional. - * @param string $content Response body. Optional. + * @param integer $httpCode HTTP status result value + * @param string $message Error message. Optional. + * @param string $content Response body. Optional. * @throws \Exception * @deprecated since 2023.09 Use BaseModule->httpError instead */ diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 5d33dc57fe..74ca11f098 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -824,7 +824,11 @@ class Worker $max_idletime = DI::config()->get('system', 'worker_max_idletime'); $last_check = DI::cache()->get(self::LAST_CHECK); $last_date = $last_check ? date('c', $last_check) : ''; - if (($max_idletime > 0) && (time() > $last_check + $max_idletime) && !DBA::exists('workerqueue', ["`done` AND `executed` > ?", DateTimeFormat::utc('now - ' . $max_idletime . ' second')])) { + if ( + ($max_idletime > 0) + && (time() > (int) $last_check + (int) $max_idletime) + && !DBA::exists('workerqueue', ["`done` AND `executed` > ?", DateTimeFormat::utc('now - ' . $max_idletime . ' second')]) + ) { DI::cache()->set(self::LAST_CHECK, time(), Duration::HOUR); Logger::info('The last worker execution had been too long ago.', ['last' => $last_check, 'last-check' => $last_date, 'seconds' => $max_idletime, 'load' => $load, 'max_load' => $maxsysload, 'active_worker' => $active, 'max_worker' => $maxqueues]); return false; @@ -1211,7 +1215,7 @@ class Worker /** * Adds tasks to the worker queue * - * @param (integer|array) priority or parameter array, strings are deprecated and are ignored + * @param integer|array $args priority or parameter array, strings are deprecated and are ignored * * next args are passed as $cmd command line * or: Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::DELETION, $drop_id); diff --git a/src/Core/Worker/Repository/Process.php b/src/Core/Worker/Repository/Process.php index 058257ffeb..146854234e 100644 --- a/src/Core/Worker/Repository/Process.php +++ b/src/Core/Worker/Repository/Process.php @@ -81,7 +81,7 @@ class Process extends BaseRepository 'pid' => $process->pid, 'hostname' => $this->currentHost, ])) { - throw new ProcessPersistenceException(sprintf('The process with PID %s doesn\'t exists.', $process->pi)); + throw new ProcessPersistenceException(sprintf('The process with PID %d doesn\'t exists.', $process->pid)); } } catch (\Exception $exception) { throw new ProcessPersistenceException(sprintf('Cannot delete process with PID %s.', $process->pid), $exception); diff --git a/src/DI.php b/src/DI.php index 5604fe9df2..8e422a129e 100644 --- a/src/DI.php +++ b/src/DI.php @@ -312,7 +312,7 @@ abstract class DI } /** - * @return LoggerInterface + * @return \Friendica\Core\Logger\Type\WorkerLogger */ public static function workerLogger() {