Fix errors in Core namespace

This commit is contained in:
Art4 2024-12-03 20:11:46 +00:00
parent 6ad1dd72d6
commit 496f0755b1
15 changed files with 79 additions and 75 deletions

View file

@ -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

View file

@ -7,6 +7,7 @@
namespace Friendica\Core;
use Exception;
use Friendica\App\Page;
use Friendica\Database\DBA;
use Friendica\DI;

View file

@ -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
*/

View file

@ -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;

View file

@ -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
{

View file

@ -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
*

View file

@ -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;

View file

@ -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);
}
/**

View file

@ -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
*/

View file

@ -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());
}

View file

@ -274,8 +274,11 @@ class StorageManager
*/
public function register(string $class): bool
{
if (is_subclass_of($class, ICanReadFromStorage::class)) {
/** @var ICanReadFromStorage $class */
if (!is_subclass_of($class, ICanReadFromStorage::class)) {
return false;
}
/** @var class-string<ICanReadFromStorage> $class */
if ($this->isValidBackend($class::getName(), $this->validBackends)) {
return true;
}
@ -286,13 +289,10 @@ class StorageManager
if ($this->config->set('storage', 'backends', $backends)) {
$this->validBackends = $backends;
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* Unregister a storage backend class
@ -305,31 +305,32 @@ class StorageManager
*/
public function unregister(string $class): bool
{
if (is_subclass_of($class, ICanReadFromStorage::class)) {
/** @var ICanReadFromStorage $class */
if (!is_subclass_of($class, ICanReadFromStorage::class)) {
return false;
}
/** @var class-string<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) {
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;
} else {
}
return false;
}
} else {
return true;
}
} else {
return false;
}
}
/**
* Move up to 5000 resources to storage $dest

View file

@ -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,7 +323,7 @@ class System
/**
* Send HTTP status header and exit.
*
* @param integer $val HTTP status result value
* @param integer $httpCode HTTP status result value
* @param string $message Error message. Optional.
* @param string $content Response body. Optional.
* @throws \Exception

View file

@ -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);

View file

@ -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);

View file

@ -312,7 +312,7 @@ abstract class DI
}
/**
* @return LoggerInterface
* @return \Friendica\Core\Logger\Type\WorkerLogger
*/
public static function workerLogger()
{