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
namespace Friendica\Core;
+use Exception;
use Friendica\App\Page;
use Friendica\Database\DBA;
use Friendica\DI;
/**
* 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
*/
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;
*/
class ConfigTransaction implements ISetConfigValuesTransactionally
{
- /** @var IManageConfigValues */
+ /** @var DatabaseConfig */
protected $config;
/** @var Cache */
protected $setCache;
/**
* 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
{
$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) {
/**
* 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
*
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;
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()
{
public static function enableWorker(string $functionName)
{
self::$type = self::TYPE_WORKER;
- self::getInstance()->setFunctionName($functionName);
+ DI::workerLogger()->setFunctionName($functionName);
}
/**
/**
* {@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
*/
{
/** @var IManageConfigValues */
protected $config;
- /** @var $fileSystem */
+ /** @var FileSystem */
protected $fileSystem;
/** @var L10n */
protected $l10n;
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());
}
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());
}
*/
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;
- }
+ if (!is_subclass_of($class, ICanReadFromStorage::class)) {
+ return false;
+ }
- $backends = $this->validBackends;
- $backends[] = $class::getName();
+ /** @var class-string<ICanReadFromStorage> $class */
+ if ($this->isValidBackend($class::getName(), $this->validBackends)) {
+ return true;
+ }
- if ($this->config->set('storage', 'backends', $backends)) {
- $this->validBackends = $backends;
- return true;
- } else {
- return false;
- }
- } else {
- return false;
+ $backends = $this->validBackends;
+ $backends[] = $class::getName();
+
+ if ($this->config->set('storage', 'backends', $backends)) {
+ $this->validBackends = $backends;
+ return true;
}
+
+ return false;
}
/**
*/
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<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) {
+ 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;
}
/**
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;
/**
* 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
*/
$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;
/**
* 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);
'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);
}
/**
- * @return LoggerInterface
+ * @return \Friendica\Core\Logger\Type\WorkerLogger
*/
public static function workerLogger()
{