aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Configuration.php28
-rw-r--r--lib/Minz/ConfigurationSetterInterface.php19
-rw-r--r--lib/Minz/Dispatcher.php25
-rw-r--r--lib/Minz/Error.php2
-rw-r--r--lib/Minz/Extension.php8
-rw-r--r--lib/Minz/ExtensionManager.php2
-rw-r--r--lib/Minz/FrontController.php6
-rw-r--r--lib/Minz/Mailer.php5
-rw-r--r--lib/Minz/Migrator.php9
-rw-r--r--lib/Minz/ModelArray.php2
-rw-r--r--lib/Minz/ModelPdo.php2
-rw-r--r--lib/Minz/Paginator.php58
-rw-r--r--lib/Minz/Request.php4
-rw-r--r--lib/Minz/Translate.php7
-rw-r--r--lib/Minz/Url.php31
-rw-r--r--lib/Minz/View.php11
-rw-r--r--lib/lib_date.php4
-rw-r--r--lib/lib_install.php12
-rw-r--r--lib/lib_rss.php41
19 files changed, 137 insertions, 139 deletions
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index 4259c4052..d641d8994 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -3,7 +3,8 @@
/**
* Manage configuration for the application.
* @property-read string $base_url
- * @property array<string|array<int,string>> $db
+ * @property array{'type'?:string,'host'?:string,'user'?:string,'password'?:string,'base'?:string,'prefix'?:string,
+ * 'connection_uri_params'?:string,'pdo_options'?:array<string|int,string|int|bool>} $db
* @property-read string $disable_update
* @property-read string $environment
* @property array<string,bool> $extensions_enabled
@@ -24,9 +25,10 @@ class Minz_Configuration {
* @param string $namespace the name of the current configuration
* @param string $config_filename the filename of the configuration
* @param string $default_filename a filename containing default values for the configuration
- * @param object $configuration_setter an optional helper to set values in configuration
+ * @param Minz_ConfigurationSetterInterface $configuration_setter an optional helper to set values in configuration
*/
- public static function register(string $namespace, string $config_filename, string $default_filename = null, object $configuration_setter = null): void {
+ public static function register(string $namespace, string $config_filename, string $default_filename = null,
+ Minz_ConfigurationSetterInterface $configuration_setter = null): void {
self::$config_list[$namespace] = new static(
$namespace, $config_filename, $default_filename, $configuration_setter
);
@@ -92,9 +94,9 @@ class Minz_Configuration {
/**
* An object which help to set good values in configuration.
- * @var object|null
+ * @var Minz_ConfigurationSetterInterface|null
*/
- private $configuration_setter = null;
+ private $configuration_setter;
/**
* Create a new Minz_Configuration object.
@@ -102,9 +104,10 @@ class Minz_Configuration {
* @param string $namespace the name of the current configuration.
* @param string $config_filename the file containing configuration values.
* @param string $default_filename the file containing default values, null by default.
- * @param object $configuration_setter an optional helper to set values in configuration
+ * @param Minz_ConfigurationSetterInterface $configuration_setter an optional helper to set values in configuration
*/
- private final function __construct(string $namespace, string $config_filename, string $default_filename = null, object $configuration_setter = null) {
+ private final function __construct(string $namespace, string $config_filename, string $default_filename = null,
+ Minz_ConfigurationSetterInterface $configuration_setter = null) {
$this->namespace = $namespace;
$this->config_filename = $config_filename;
$this->default_filename = $default_filename;
@@ -127,16 +130,15 @@ class Minz_Configuration {
/**
* Set a configuration setter for the current configuration.
- * @param object|null $configuration_setter the setter to call when modifying data. It
- * must implement an handle($key, $value) method.
+ * @param Minz_ConfigurationSetterInterface|null $configuration_setter the setter to call when modifying data.
*/
- public function _configurationSetter(?object $configuration_setter): void {
+ public function _configurationSetter(?Minz_ConfigurationSetterInterface $configuration_setter): void {
if (is_callable(array($configuration_setter, 'handle'))) {
$this->configuration_setter = $configuration_setter;
}
}
- public function configurationSetter(): object {
+ public function configurationSetter(): ?Minz_ConfigurationSetterInterface {
return $this->configuration_setter;
}
@@ -181,11 +183,11 @@ class Minz_Configuration {
* @param mixed $value the value to set. If null, the key is removed from the configuration.
*/
public function _param(string $key, $value = null): void {
- if (!is_null($this->configuration_setter) && $this->configuration_setter->support($key)) {
+ if ($this->configuration_setter !== null && $this->configuration_setter->support($key)) {
$this->configuration_setter->handle($this->data, $key, $value);
} elseif (isset($this->data[$key]) && is_null($value)) {
unset($this->data[$key]);
- } elseif (!is_null($value)) {
+ } elseif ($value !== null) {
$this->data[$key] = $value;
}
}
diff --git a/lib/Minz/ConfigurationSetterInterface.php b/lib/Minz/ConfigurationSetterInterface.php
new file mode 100644
index 000000000..ac8c154ba
--- /dev/null
+++ b/lib/Minz/ConfigurationSetterInterface.php
@@ -0,0 +1,19 @@
+<?php
+
+interface Minz_ConfigurationSetterInterface {
+
+ /**
+ * Return whether the given key is supported by this setter.
+ * @param string $key the key to test.
+ * @return bool true if the key is supported, false otherwise.
+ */
+ public function support(string $key): bool;
+
+ /**
+ * Set the given key in data with the current value.
+ * @param array<string,mixed> $data an array containing the list of all configuration data.
+ * @param string $key the key to update.
+ * @param mixed $value the value to set.
+ */
+ public function handle(&$data, string $key, $value): void;
+}
diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php
index 128207025..abc7efe21 100644
--- a/lib/Minz/Dispatcher.php
+++ b/lib/Minz/Dispatcher.php
@@ -87,19 +87,21 @@ class Minz_Dispatcher {
$controller_name = 'FreshRSS_' . $base_name . '_Controller';
}
- if (!class_exists ($controller_name)) {
+ if (!class_exists($controller_name)) {
throw new Minz_ControllerNotExistException (
Minz_Exception::ERROR
);
}
- $this->controller = new $controller_name ();
+ $controller = new $controller_name();
- if (! ($this->controller instanceof Minz_ActionController)) {
+ if (!($controller instanceof Minz_ActionController)) {
throw new Minz_ControllerNotActionControllerException (
$controller_name,
Minz_Exception::ERROR
);
}
+
+ $this->controller = $controller;
}
/**
@@ -108,20 +110,15 @@ class Minz_Dispatcher {
* @throws Minz_ActionException if the action cannot be executed on the controller
*/
private function launchAction(string $action_name): void {
- if (!is_callable (array (
- $this->controller,
- $action_name
- ))) {
+ $call = [$this->controller, $action_name];
+ if (!is_callable($call)) {
throw new Minz_ActionException (
- get_class ($this->controller),
+ get_class($this->controller),
$action_name,
Minz_Exception::ERROR
);
}
- call_user_func (array (
- $this->controller,
- $action_name
- ));
+ call_user_func($call);
}
/**
@@ -140,9 +137,9 @@ class Minz_Dispatcher {
* Return if a controller is registered.
*
* @param string $base_name the base name of the controller.
- * @return boolean true if the controller has been registered, false else.
+ * @return bool true if the controller has been registered, false else.
*/
- public static function isRegistered(string $base_name) {
+ public static function isRegistered(string $base_name): bool {
return isset(self::$registrations[$base_name]);
}
diff --git a/lib/Minz/Error.php b/lib/Minz/Error.php
index e23499a10..15be7b8b4 100644
--- a/lib/Minz/Error.php
+++ b/lib/Minz/Error.php
@@ -52,7 +52,7 @@ class Minz_Error {
* @param array<string,string>|string $logs logs sorted by category (error, warning, notice)
* @return array<string> list of matching logs, without the category, according to environment preferences (production / development)
*/
- private static function processLogs($logs) {
+ private static function processLogs($logs): array {
$conf = Minz_Configuration::get('system');
$env = $conf->environment;
$logs_ok = array ();
diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php
index e95fe7160..8fe8c38b4 100644
--- a/lib/Minz/Extension.php
+++ b/lib/Minz/Extension.php
@@ -217,7 +217,7 @@ abstract class Minz_Extension {
}
/** @param 'system'|'user' $type */
- private function isConfigurationEnabled($type): bool {
+ private function isConfigurationEnabled(string $type): bool {
if (!class_exists('FreshRSS_Context', false)) {
return false;
}
@@ -229,7 +229,7 @@ abstract class Minz_Extension {
}
/** @param 'system'|'user' $type */
- private function isExtensionConfigured($type): bool {
+ private function isExtensionConfigured(string $type): bool {
switch ($type) {
case 'system':
$conf = FreshRSS_Context::$user_conf;
@@ -248,7 +248,7 @@ abstract class Minz_Extension {
}
/**
- * @param 'system'|'user' $type
+ * @phpstan-param 'system'|'user' $type
* @return array<string,mixed>
*/
private function getConfiguration(string $type): array {
@@ -338,7 +338,7 @@ abstract class Minz_Extension {
$this->user_configuration = $configuration;
}
- /** @param 'system'|'user' $type */
+ /** @phpstan-param 'system'|'user' $type */
private function removeConfiguration(string $type): void {
if (!$this->isConfigurationEnabled($type)) {
return;
diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php
index 9c0eaf001..0e1c72885 100644
--- a/lib/Minz/ExtensionManager.php
+++ b/lib/Minz/ExtensionManager.php
@@ -364,7 +364,7 @@ final class Minz_ExtensionManager {
foreach (self::$hook_list[$hook_name]['list'] as $function) {
$result = call_user_func($function, $arg);
- if (is_null($result)) {
+ if ($result === null) {
break;
}
diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php
index 4837f89c1..3268b5763 100644
--- a/lib/Minz/FrontController.php
+++ b/lib/Minz/FrontController.php
@@ -39,11 +39,11 @@ class Minz_FrontController {
Minz_Request::init();
$url = Minz_Url::build();
- $url['params'] = array_merge (
- $url['params'],
+ $url['params'] = array_merge(
+ empty($url['params']) || !is_array($url['params']) ? [] : $url['params'],
$_POST
);
- Minz_Request::forward ($url);
+ Minz_Request::forward($url);
} catch (Minz_Exception $e) {
Minz_Log::error($e->getMessage());
self::killApp($e->getMessage());
diff --git a/lib/Minz/Mailer.php b/lib/Minz/Mailer.php
index ba434ec8f..cf6c64bad 100644
--- a/lib/Minz/Mailer.php
+++ b/lib/Minz/Mailer.php
@@ -44,7 +44,7 @@ class Minz_Mailer {
*/
public function __construct () {
$this->view = new Minz_View();
- $this->view->_layout(false);
+ $this->view->_layout(null);
$this->view->attributeParams();
$conf = Minz_Configuration::get('system');
@@ -66,10 +66,9 @@ class Minz_Mailer {
*
* @param string $to The recipient of the email
* @param string $subject The subject of the email
- *
* @return bool true on success, false if a SMTP error happens
*/
- public function mail($to, $subject) {
+ public function mail(string $to, string $subject): bool {
ob_start();
$this->view->render();
$body = ob_get_contents();
diff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.php
index 661bc9c5d..ef4bce48f 100644
--- a/lib/Minz/Migrator.php
+++ b/lib/Minz/Migrator.php
@@ -38,11 +38,11 @@ class Minz_Migrator
$applied_migrations = array_filter(explode("\n", $applied_migrations));
$migration_files = scandir($migrations_path);
- $migration_files = array_filter($migration_files, function ($filename) {
+ $migration_files = array_filter($migration_files, static function (string $filename) {
$file_extension = pathinfo($filename, PATHINFO_EXTENSION);
return $file_extension === 'php';
});
- $migration_versions = array_map(function ($filename) {
+ $migration_versions = array_map(static function (string $filename) {
return basename($filename, '.php');
}, $migration_files);
@@ -225,9 +225,8 @@ class Minz_Migrator
}
/**
- * @return boolean Return true if the application is up-to-date, false
- * otherwise. If no migrations are registered, it always
- * returns true.
+ * @return bool Return true if the application is up-to-date, false otherwise.
+ * If no migrations are registered, it always returns true.
*/
public function upToDate(): bool {
// Counting versions is enough since we cannot apply a version which
diff --git a/lib/Minz/ModelArray.php b/lib/Minz/ModelArray.php
index 0d8b71f91..d2f518344 100644
--- a/lib/Minz/ModelArray.php
+++ b/lib/Minz/ModelArray.php
@@ -19,7 +19,7 @@ class Minz_ModelArray {
* @param string $filename le nom du fichier à ouvrir contenant un tableau
* Remarque : $array sera obligatoirement un tableau
*/
- public function __construct ($filename) {
+ public function __construct(string $filename) {
$this->filename = $filename;
}
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php
index 0e813ddca..dc3d0a42c 100644
--- a/lib/Minz/ModelPdo.php
+++ b/lib/Minz/ModelPdo.php
@@ -102,7 +102,7 @@ class Minz_ModelPdo {
* @throws Minz_ConfigurationNamespaceException
* @throws Minz_PDOConnectionException
*/
- public function __construct($currentUser = null, $currentPdo = null) {
+ public function __construct(?string $currentUser = null, ?Minz_Pdo $currentPdo = null) {
if ($currentUser === null) {
$currentUser = Minz_User::name();
}
diff --git a/lib/Minz/Paginator.php b/lib/Minz/Paginator.php
index e11dda11c..77bc3e5e0 100644
--- a/lib/Minz/Paginator.php
+++ b/lib/Minz/Paginator.php
@@ -37,11 +37,11 @@ class Minz_Paginator {
* Constructeur
* @param array<Minz_Model> $items les éléments à gérer
*/
- public function __construct ($items) {
- $this->_items ($items);
- $this->_nbItems (count ($this->items (true)));
- $this->_nbItemsPerPage ($this->nbItemsPerPage);
- $this->_currentPage ($this->currentPage);
+ public function __construct(array $items) {
+ $this->_items($items);
+ $this->_nbItems(count($this->items(true)));
+ $this->_nbItemsPerPage($this->nbItemsPerPage);
+ $this->_currentPage($this->currentPage);
}
/**
@@ -49,25 +49,25 @@ class Minz_Paginator {
* @param string $view nom du fichier de vue situé dans /app/views/helpers/
* @param int $getteur variable de type $_GET[] permettant de retrouver la page
*/
- public function render ($view, $getteur) {
+ public function render(string $view, int $getteur = 0): void {
$view = APP_PATH . '/views/helpers/' . $view;
- if (file_exists ($view)) {
- include ($view);
+ if (file_exists($view)) {
+ include($view);
}
}
/**
* Permet de retrouver la page d'un élément donné
* @param Minz_Model $item l'élément à retrouver
- * @return float|false la page à laquelle se trouve l’élément, false si non trouvé
+ * @return int|false la page à laquelle se trouve l’élément, false si non trouvé
*/
- public function pageByItem ($item) {
+ public function pageByItem($item) {
$i = 0;
do {
if ($item == $this->items[$i]) {
- return ceil(($i + 1) / $this->nbItemsPerPage);
+ return (int)(ceil(($i + 1) / $this->nbItemsPerPage));
}
$i++;
} while ($i < $this->nbItems());
@@ -80,7 +80,7 @@ class Minz_Paginator {
* @param Minz_Model $item the element to search
* @return int|false the position of the element, or false if not found
*/
- public function positionByItem ($item) {
+ public function positionByItem($item) {
$i = 0;
do {
@@ -96,9 +96,9 @@ class Minz_Paginator {
/**
* Permet de récupérer un item par sa position
* @param int $pos la position de l'élément
- * @return mixed item situé à $pos (dernier item si $pos<0, 1er si $pos>=count($items))
+ * @return Minz_Model item situé à $pos (dernier item si $pos<0, 1er si $pos>=count($items))
*/
- public function itemByPosition ($pos) {
+ public function itemByPosition(int $pos): Minz_Model {
if ($pos < 0) {
$pos = $this->nbItems () - 1;
}
@@ -116,7 +116,7 @@ class Minz_Paginator {
* @param bool $all si à true, retourne tous les éléments sans prendre en compte la pagination
* @return array<Minz_Model>
*/
- public function items ($all = false) {
+ public function items(bool $all = false): array {
$array = array ();
$nbItems = $this->nbItems ();
@@ -141,30 +141,28 @@ class Minz_Paginator {
return $array;
}
- public function nbItemsPerPage () {
+ public function nbItemsPerPage(): int {
return $this->nbItemsPerPage;
}
- public function currentPage () {
+ public function currentPage(): int {
return $this->currentPage;
}
- public function nbPage () {
+ public function nbPage(): int {
return $this->nbPage;
}
- public function nbItems () {
+ public function nbItems(): int {
return $this->nbItems;
}
/**
* SETTEURS
*/
- public function _items ($items) {
- if (is_array ($items)) {
- $this->items = $items;
- }
-
- $this->_nbPage ();
+ /** @param array<Minz_Model> $items */
+ public function _items(?array $items): void {
+ $this->items = $items ?? [];
+ $this->_nbPage();
}
- public function _nbItemsPerPage ($nbItemsPerPage) {
+ public function _nbItemsPerPage(int $nbItemsPerPage): void {
if ($nbItemsPerPage > $this->nbItems ()) {
$nbItemsPerPage = $this->nbItems ();
}
@@ -173,21 +171,21 @@ class Minz_Paginator {
}
$this->nbItemsPerPage = $nbItemsPerPage;
- $this->_nbPage ();
+ $this->_nbPage();
}
- public function _currentPage ($page) {
+ public function _currentPage(int $page): void {
if ($page < 1 || ($page > $this->nbPage && $this->nbPage > 0)) {
throw new Minz_CurrentPagePaginationException($page);
}
$this->currentPage = $page;
}
- private function _nbPage () {
+ private function _nbPage(): void {
if ($this->nbItemsPerPage > 0) {
$this->nbPage = (int)ceil($this->nbItems() / $this->nbItemsPerPage);
}
}
- public function _nbItems ($value) {
+ public function _nbItems(int $value): void {
$this->nbItems = $value;
}
}
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index 7957610e2..ca9957eab 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -298,7 +298,7 @@ class Minz_Request {
* localhost address.
*
* @param string $address the address to test, can be an IP or a URL.
- * @return boolean true if server is accessible, false otherwise.
+ * @return bool true if server is accessible, false otherwise.
* @todo improve test with a more valid technique (e.g. test with an external server?)
*/
public static function serverIsPublic(string $address): bool {
@@ -360,7 +360,7 @@ class Minz_Request {
$requests = Minz_Session::param('requests');
if ($requests) {
//Delete abandoned notifications
- $requests = array_filter($requests, function ($r) { return isset($r['time']) && $r['time'] > time() - 3600; });
+ $requests = array_filter($requests, static function (array $r) { return isset($r['time']) && $r['time'] > time() - 3600; });
$requestId = self::requestId();
if (!empty($requests[$requestId]['notification'])) {
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php
index e4c1020d5..0d704a85f 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -133,8 +133,8 @@ class Minz_Translate {
}
$list_i18n_files = array_values(array_diff(
- scandir($lang_path),
- array('..', '.')
+ scandir($lang_path) ?: [],
+ ['..', '.']
));
// Each file basename correspond to a top-level i18n key. For each of
@@ -199,8 +199,7 @@ class Minz_Translate {
// If $translates[$top_level] is null it means we have to load the
// corresponding files.
- if (!isset(self::$translates[$top_level]) ||
- is_null(self::$translates[$top_level])) {
+ if (empty(self::$translates[$top_level])) {
$res = self::loadKey($top_level);
if (!$res) {
return $key;
diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php
index 1350973c1..f0df93b69 100644
--- a/lib/Minz/Url.php
+++ b/lib/Minz/Url.php
@@ -60,7 +60,7 @@ class Minz_Url {
* @param string $encodage pour indiquer comment encoder les & (& ou &amp; pour html)
* @return string uri sous la forme ?key=value&key2=value2
*/
- private static function printUri($url, string $encodage): string {
+ private static function printUri(array $url, string $encodage): string {
$uri = '';
$separator = '?';
$anchor = '';
@@ -108,23 +108,15 @@ class Minz_Url {
/**
* Check that all array elements representing the controller URL are OK
- * @param array<string,array<string,string>> $url controller URL as array
+ * @param array<string,string|array<string,mixed>> $url controller URL as array
* @return array{'c':string,'a':string,'params':array<string,mixed>} Verified controller URL as array
*/
- public static function checkControllerUrl(array $url) {
- $url_checked = $url;
-
- if (empty($url['c'])) {
- $url_checked['c'] = Minz_Request::defaultControllerName();
- }
- if (empty($url['a'])) {
- $url_checked['a'] = Minz_Request::defaultActionName();
- }
- if (empty($url['params'])) {
- $url_checked['params'] = [];
- }
-
- return $url_checked;
+ public static function checkControllerUrl(array $url): array {
+ return [
+ 'c' => empty($url['c']) || !is_string($url['c']) ? Minz_Request::defaultControllerName() : $url['c'],
+ 'a' => empty($url['a']) || !is_string($url['a']) ? Minz_Request::defaultActionName() : $url['a'],
+ 'params' => empty($url['params']) || !is_array($url['params']) ? [] : $url['params'],
+ ];
}
/** @param array<string,string|array<string,string>>|null $url */
@@ -139,7 +131,10 @@ class Minz_Url {
}
}
- /** @return array<string,string|array<string,string>> */
+ /**
+ * @phpstan-return array{'c'?:string,'a'?:string,'params'?:array<string,mixed>}
+ * @return array<string,string|array<string,string>>
+ */
public static function unserialize(string $url = ''): array {
try {
return json_decode(base64_decode($url), true, JSON_THROW_ON_ERROR) ?? [];
@@ -150,7 +145,7 @@ class Minz_Url {
/**
* Returns an array representing the URL as passed in the address bar
- * @return array<string,string|array<string,string>> URL representation
+ * @return array{'c'?:string,'a'?:string,'params'?:array<string,mixed>} URL representation
*/
public static function build(): array {
$url = [
diff --git a/lib/Minz/View.php b/lib/Minz/View.php
index 3b18c1dba..70b745ea4 100644
--- a/lib/Minz/View.php
+++ b/lib/Minz/View.php
@@ -22,7 +22,7 @@ class Minz_View {
private static $title = '';
/** @var array<array{'media':string,'url':string}> */
private static $styles = [];
- /** @var array<array{'url':string,'id':string,'defer':string,'async':string}> */
+ /** @var array<array{'url':string,'id':string,'defer':bool,'async':bool}> */
private static $scripts = [];
/** @var string|array{'dark'?:string,'light'?:string,'default'?:string} */
private static $themeColors;
@@ -83,7 +83,7 @@ class Minz_View {
* The file is searched inside list of $base_pathnames.
*
* @param string $filename the name of the file to include.
- * @return boolean true if the file has been included, false else.
+ * @return bool true if the file has been included, false else.
*/
private function includeFile(string $filename): bool {
// We search the filename in the list of base pathnames. Only the first view
@@ -158,9 +158,9 @@ class Minz_View {
/**
* Choose the current view layout.
- * @param string|false $layout the layout name to use, false to use no layouts.
+ * @param string|null $layout the layout name to use, false to use no layouts.
*/
- public function _layout($layout): void {
+ public function _layout(?string $layout): void {
if ($layout) {
$this->layout_filename = self::LAYOUT_PATH_NAME . $layout . '.phtml';
} else {
@@ -178,7 +178,7 @@ class Minz_View {
if ($use) {
$this->_layout(self::LAYOUT_DEFAULT);
} else {
- $this->_layout(false);
+ $this->_layout(null);
}
}
@@ -326,7 +326,6 @@ class Minz_View {
/**
* Management of parameters added to the view
- * @param string $key
* @param mixed $value
*/
public static function _param(string $key, $value): void {
diff --git a/lib/lib_date.php b/lib/lib_date.php
index 00356927f..d9e1610e6 100644
--- a/lib/lib_date.php
+++ b/lib/lib_date.php
@@ -34,7 +34,7 @@ example('PT6M/');
example('PT7S/');
example('P1DT1H/');
-function example($dateInterval) {
+function example(string $dateInterval) {
$dateIntervalArray = parseDateInterval($dateInterval);
echo $dateInterval, "\t=>\t",
$dateIntervalArray[0] == null ? 'null' : @date('c', $dateIntervalArray[0]), '/',
@@ -84,7 +84,7 @@ function _dateRelative(?string $d1, ?string $d2): ?string {
* @return array{int|null|false,int|null|false} an array with the minimum and maximum Unix timestamp of this interval,
* or null if open interval, or false if error.
*/
-function parseDateInterval(string $dateInterval) {
+function parseDateInterval(string $dateInterval): array {
$dateInterval = trim($dateInterval);
$dateInterval = str_replace('--', '/', $dateInterval);
$dateInterval = strtoupper($dateInterval);
diff --git a/lib/lib_install.php b/lib/lib_install.php
index 18f4a732a..23c902440 100644
--- a/lib/lib_install.php
+++ b/lib/lib_install.php
@@ -1,7 +1,7 @@
<?php
-Minz_Configuration::register('default_system', join_path(FRESHRSS_PATH, 'config.default.php'));
-Minz_Configuration::register('default_user', join_path(FRESHRSS_PATH, 'config-user.default.php'));
+FreshRSS_SystemConfiguration::register('default_system', join_path(FRESHRSS_PATH, 'config.default.php'));
+FreshRSS_UserConfiguration::register('default_user', join_path(FRESHRSS_PATH, 'config-user.default.php'));
/** @return array<string,string> */
function checkRequirements(string $dbType = ''): array {
@@ -76,7 +76,7 @@ function checkRequirements(string $dbType = ''): array {
}
function generateSalt(): string {
- return sha1(uniqid('' . mt_rand(), true).implode('', stat(__FILE__)));
+ return sha1(uniqid('' . mt_rand(), true).implode('', stat(__FILE__) ?: []));
}
function initDb(): string {
@@ -88,10 +88,14 @@ function initDb(): string {
$db['pdo_options'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$conf->db = $db; //TODO: Remove this Minz limitation "Indirect modification of overloaded property"
+ if (empty($db['type'])) {
+ $db['type'] = 'sqlite';
+ }
+
//Attempt to auto-create database if it does not already exist
if ($db['type'] !== 'sqlite') {
Minz_ModelPdo::$usesSharedPdo = false;
- $dbBase = isset($db['base']) ? $db['base'] : '';
+ $dbBase = $db['base'] ?? '';
//For first connection, use default database for PostgreSQL, empty database for MySQL / MariaDB:
$db['base'] = $db['type'] === 'pgsql' ? 'postgres' : '';
$conf->db = $db;
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 1babc8d63..22af2729b 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -132,11 +132,7 @@ function checkUrl(string $url, bool $fixScheme = true) {
}
}
-/**
- * @param string $text
- * @return string
- */
-function safe_ascii($text) {
+function safe_ascii(string $text): string {
return filter_var($text, FILTER_DEFAULT, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH) ?: '';
}
@@ -154,12 +150,7 @@ if (function_exists('mb_convert_encoding')) {
}
}
-/**
- * @param string $text
- * @param bool $extended
- * @return string
- */
-function escapeToUnicodeAlternative($text, $extended = true) {
+function escapeToUnicodeAlternative(string $text, bool $extended = true): string {
$text = htmlspecialchars_decode($text, ENT_QUOTES);
//Problematic characters
@@ -176,7 +167,8 @@ function escapeToUnicodeAlternative($text, $extended = true) {
return trim(str_replace($problem, $replace, $text));
}
-function format_number(float $n, int $precision = 0): string {
+/** @param int|float $n */
+function format_number($n, int $precision = 0): string {
// number_format does not seem to be Unicode-compatible
return str_replace(' ', ' ', // Thin non-breaking space
number_format($n, $precision, '.', ' ')
@@ -255,7 +247,7 @@ function sensitive_log($log) {
/**
* @param array<string,mixed> $attributes
*/
-function customSimplePie($attributes = array()): SimplePie {
+function customSimplePie(array $attributes = array()): SimplePie {
if (FreshRSS_Context::$system_conf === null) {
throw new FreshRSS_Context_Exception('System configuration not initialised!');
}
@@ -339,10 +331,8 @@ function customSimplePie($attributes = array()): SimplePie {
return $simplePie;
}
-/**
- * @param string $data
- */
-function sanitizeHTML($data, string $base = '', ?int $maxLength = null): string {
+/** @param string $data */
+function sanitizeHTML(string $data, string $base = '', ?int $maxLength = null): string {
if (!is_string($data) || ($maxLength !== null && $maxLength <= 0)) {
return '';
}
@@ -579,7 +569,7 @@ function listUsers(): array {
* Return if the maximum number of registrations has been reached.
* Note a max_registrations of 0 means there is no limit.
*
- * @return boolean true if number of users >= max registrations, false else.
+ * @return bool true if number of users >= max registrations, false else.
*/
function max_registrations_reached(): bool {
if (FreshRSS_Context::$system_conf === null) {
@@ -601,13 +591,13 @@ function max_registrations_reached(): bool {
* @param string $username the name of the user of which we want the configuration.
* @return FreshRSS_UserConfiguration|null object, or null if the configuration cannot be loaded.
*/
-function get_user_configuration(string $username) {
+function get_user_configuration(string $username): ?FreshRSS_UserConfiguration {
if (!FreshRSS_user_Controller::checkUsername($username)) {
return null;
}
$namespace = 'user_' . $username;
try {
- Minz_Configuration::register($namespace,
+ FreshRSS_UserConfiguration::register($namespace,
USERS_PATH . '/' . $username . '/config.php',
FRESHRSS_PATH . '/config-user.default.php');
} catch (Minz_ConfigurationNamespaceException $e) {
@@ -618,10 +608,7 @@ function get_user_configuration(string $username) {
return null;
}
- /**
- * @var FreshRSS_UserConfiguration $user_conf
- */
- $user_conf = Minz_Configuration::get($namespace);
+ $user_conf = FreshRSS_UserConfiguration::get($namespace);
return $user_conf;
}
@@ -644,7 +631,7 @@ function ipToBits(string $ip): string {
*
* @param string $ip the IP that we want to verify (ex: 192.168.16.1)
* @param string $range the range to check against (ex: 192.168.16.0/24)
- * @return boolean true if the IP is in the range, otherwise false
+ * @return bool true if the IP is in the range, otherwise false
*/
function checkCIDR(string $ip, string $range): bool {
$binary_ip = ipToBits($ip);
@@ -663,7 +650,7 @@ function checkCIDR(string $ip, string $range): bool {
* This uses the REMOTE_ADDR header to determine the sender's IP
* and the configuration option "trusted_sources" to get an array of the authorized ranges
*
- * @return boolean, true if the sender's IP is in one of the ranges defined in the configuration, else false
+ * @return bool, true if the sender's IP is in one of the ranges defined in the configuration, else false
*/
function checkTrustedIP(): bool {
if (FreshRSS_Context::$system_conf === null) {
@@ -840,7 +827,7 @@ const SHORTCUT_KEYS = [
function getNonStandardShortcuts(array $shortcuts): array {
$standard = strtolower(implode(' ', SHORTCUT_KEYS));
- $nonStandard = array_filter($shortcuts, function ($shortcut) use ($standard) {
+ $nonStandard = array_filter($shortcuts, static function (string $shortcut) use ($standard) {
$shortcut = trim($shortcut);
return $shortcut !== '' & stripos($standard, $shortcut) === false;
});