aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-09-06 09:06:46 +0200
committerGravatar GitHub <noreply@github.com> 2024-09-06 09:06:46 +0200
commita81656c3ed5b8fe0f31794a4fbe0d1a907fca8e8 (patch)
tree8bf49bd876aaebc985a9fb1214863190a799cbee /lib
parent8f7c3473a76809efc88814253722c76f0cc8eb04 (diff)
Upgrade to PHP 8.1 (#6711)
* Upgrade to PHP 8.1 As discussed in https://github.com/FreshRSS/FreshRSS/discussions/5474 https://www.php.net/releases/8.0/en.php https://www.php.net/releases/8.1/en.php Upgrade to available native type declarations https://php.net/language.types.declarations Upgrade to https://phpunit.de/announcements/phpunit-10.html which requires PHP 8.1+ (good timing, as version 9 was not maintained anymore) Upgrade `:oldest` Docker dev image to oldest Alpine version supporting PHP 8.1: Alpine 3.16, which includes PHP 8.1.22. * Include 6736 https://github.com/FreshRSS/FreshRSS/pull/6736
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Configuration.php12
-rw-r--r--lib/Minz/ConfigurationSetterInterface.php2
-rw-r--r--lib/Minz/Extension.php16
-rw-r--r--lib/Minz/ExtensionManager.php2
-rw-r--r--lib/Minz/FrontController.php3
-rw-r--r--lib/Minz/Helper.php5
-rw-r--r--lib/Minz/Log.php1
-rw-r--r--lib/Minz/Mailer.php4
-rw-r--r--lib/Minz/Migrator.php5
-rw-r--r--lib/Minz/ModelPdo.php2
-rw-r--r--lib/Minz/Paginator.php4
-rw-r--r--lib/Minz/Pdo.php22
-rw-r--r--lib/Minz/PdoMysql.php5
-rw-r--r--lib/Minz/PdoSqlite.php5
-rw-r--r--lib/Minz/Request.php4
-rw-r--r--lib/Minz/Session.php2
-rw-r--r--lib/Minz/Translate.php4
-rw-r--r--lib/Minz/Url.php11
-rw-r--r--lib/Minz/View.php7
-rw-r--r--lib/lib_date.php2
-rw-r--r--lib/lib_rss.php43
21 files changed, 34 insertions, 127 deletions
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index 7205f3009..89aea4fae 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -56,10 +56,9 @@ class Minz_Configuration {
* Return the configuration related to a given namespace.
*
* @param string $namespace the name of the configuration to get.
- * @return static object
* @throws Minz_ConfigurationNamespaceException if the namespace does not exist.
*/
- public static function get(string $namespace) {
+ public static function get(string $namespace): static {
if (!isset(self::$config_list[$namespace])) {
throw new Minz_ConfigurationNamespaceException(
$namespace . ' namespace does not exist'
@@ -156,7 +155,7 @@ class Minz_Configuration {
* @param mixed $default default value to return if key does not exist.
* @return array|mixed value corresponding to the key.
*/
- public function param(string $key, $default = null) {
+ public function param(string $key, mixed $default = null): mixed {
if (isset($this->data[$key])) {
return $this->data[$key];
} elseif (!is_null($default)) {
@@ -171,7 +170,7 @@ class Minz_Configuration {
* A wrapper for param().
* @return array|mixed
*/
- public function __get(string $key) {
+ public function __get(string $key): mixed {
return $this->param($key);
}
@@ -181,7 +180,7 @@ class Minz_Configuration {
* @param string $key the param name to set.
* @param mixed $value the value to set. If null, the key is removed from the configuration.
*/
- public function _param(string $key, $value = null): void {
+ public function _param(string $key, mixed $value = null): void {
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)) {
@@ -193,9 +192,8 @@ class Minz_Configuration {
/**
* A wrapper for _param().
- * @param mixed $value
*/
- public function __set(string $key, $value): void {
+ public function __set(string $key, mixed $value): void {
$this->_param($key, $value);
}
diff --git a/lib/Minz/ConfigurationSetterInterface.php b/lib/Minz/ConfigurationSetterInterface.php
index f141a1a6f..451d4cb0e 100644
--- a/lib/Minz/ConfigurationSetterInterface.php
+++ b/lib/Minz/ConfigurationSetterInterface.php
@@ -16,5 +16,5 @@ interface Minz_ConfigurationSetterInterface {
* @param string $key the key to update.
* @param mixed $value the value to set.
*/
- public function handle(&$data, string $key, $value): void;
+ public function handle(array &$data, string $key, mixed $value): void;
}
diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php
index 95d28af8a..69b9c569c 100644
--- a/lib/Minz/Extension.php
+++ b/lib/Minz/Extension.php
@@ -105,7 +105,7 @@ abstract class Minz_Extension {
*
* @return string|false html content from ext_dir/configure.phtml, false if it does not exist.
*/
- final public function getConfigureView() {
+ final public function getConfigureView(): string|false {
$filename = $this->path . '/configure.phtml';
if (!file_exists($filename)) {
return false;
@@ -146,7 +146,7 @@ abstract class Minz_Extension {
return $this->version;
}
/** @return 'system'|'user' */
- final public function getType() {
+ final public function getType(): string {
return $this->type;
}
@@ -296,11 +296,7 @@ abstract class Minz_Extension {
return [];
}
- /**
- * @param mixed $default
- * @return mixed
- */
- final public function getSystemConfigurationValue(string $key, $default = null) {
+ final public function getSystemConfigurationValue(string $key, mixed $default = null): mixed {
if (!is_array($this->system_configuration)) {
$this->system_configuration = $this->getSystemConfiguration();
}
@@ -311,11 +307,7 @@ abstract class Minz_Extension {
return $default;
}
- /**
- * @param mixed $default
- * @return mixed
- */
- final public function getUserConfigurationValue(string $key, $default = null) {
+ final public function getUserConfigurationValue(string $key, mixed $default = null): mixed {
if (!is_array($this->user_configuration)) {
$this->user_configuration = $this->getUserConfiguration();
}
diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php
index d9e38955b..2d7c92d6b 100644
--- a/lib/Minz/ExtensionManager.php
+++ b/lib/Minz/ExtensionManager.php
@@ -369,7 +369,7 @@ final class Minz_ExtensionManager {
* @return mixed|null final chained result of the hooks. If nothing is changed,
* the initial argument is returned.
*/
- private static function callOneToOne(string $hook_name, $arg) {
+ private static function callOneToOne(string $hook_name, mixed $arg): mixed {
$result = $arg;
foreach (self::$hook_list[$hook_name]['list'] as $function) {
$result = call_user_func($function, $arg);
diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php
index e57fb69c6..3a86d2d6d 100644
--- a/lib/Minz/FrontController.php
+++ b/lib/Minz/FrontController.php
@@ -79,9 +79,8 @@ class Minz_FrontController {
/**
* Kills the programme
- * @return never
*/
- public static function killApp(string $txt = '') {
+ public static function killApp(string $txt = ''): never {
header('HTTP/1.1 500 Internal Server Error', true, 500);
if (function_exists('errorMessageInfo')) {
//If the application has defined a custom error message function
diff --git a/lib/Minz/Helper.php b/lib/Minz/Helper.php
index 50243ded0..91c1bdc00 100644
--- a/lib/Minz/Helper.php
+++ b/lib/Minz/Helper.php
@@ -18,11 +18,8 @@ final class Minz_Helper {
* @phpstan-template T of mixed
* @phpstan-param T $var
* @phpstan-return T
- *
- * @param mixed $var
- * @return mixed
*/
- public static function htmlspecialchars_utf8($var) {
+ public static function htmlspecialchars_utf8(mixed $var): mixed {
if (is_array($var)) {
// @phpstan-ignore argument.type, return.type
return array_map([self::class, 'htmlspecialchars_utf8'], $var);
diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php
index 648c2c663..8bf193ffe 100644
--- a/lib/Minz/Log.php
+++ b/lib/Minz/Log.php
@@ -76,7 +76,6 @@ class Minz_Log {
* This method can be called multiple times for one script execution, but its result will not change unless
* you call clearstatcache() in between. We won’t do do that for performance reasons.
*
- * @param string $file_name
* @throws Minz_PermissionDeniedException
*/
protected static function ensureMaxLogSize(string $file_name): void {
diff --git a/lib/Minz/Mailer.php b/lib/Minz/Mailer.php
index 8e1211807..c657bd486 100644
--- a/lib/Minz/Mailer.php
+++ b/lib/Minz/Mailer.php
@@ -18,10 +18,6 @@ use PHPMailer\PHPMailer\Exception;
* $this->view->_path('user_mailer/email_need_validation.txt.php')
* ```
*
- * Minz_Mailer uses the PHPMailer library under the hood. The latter requires
- * PHP >= 5.5 to work. If you instantiate a Minz_Mailer with PHP < 5.5, a
- * warning will be logged.
- *
* The email is sent by calling the `mail` method.
*/
class Minz_Mailer {
diff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.php
index c1978dc69..39c834765 100644
--- a/lib/Minz/Migrator.php
+++ b/lib/Minz/Migrator.php
@@ -19,9 +19,6 @@ class Minz_Migrator
/**
* Execute a list of migrations, skipping versions indicated in a file
*
- * @param string $migrations_path
- * @param string $applied_migrations_path
- *
* @return true|string Returns true if execute succeeds to apply
* migrations, or a string if it fails.
* @throws DomainException if there is no migrations corresponding to the
@@ -31,7 +28,7 @@ class Minz_Migrator
*
* @throws BadFunctionCallException if a callback isn’t callable.
*/
- public static function execute(string $migrations_path, string $applied_migrations_path) {
+ public static function execute(string $migrations_path, string $applied_migrations_path): string|bool {
$applied_migrations = @file_get_contents($applied_migrations_path);
if ($applied_migrations === false) {
return "Cannot open the {$applied_migrations_path} file";
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php
index b39ae2f81..f27ae5dc7 100644
--- a/lib/Minz/ModelPdo.php
+++ b/lib/Minz/ModelPdo.php
@@ -86,8 +86,6 @@ class Minz_ModelPdo {
/**
* Create the connection to the database using the variables
* HOST, BASE, USER and PASS variables defined in the configuration file
- * @param string|null $currentUser
- * @param Minz_Pdo|null $currentPdo
* @throws Minz_ConfigurationException
* @throws Minz_PDOConnectionException
*/
diff --git a/lib/Minz/Paginator.php b/lib/Minz/Paginator.php
index 3b3c0961e..727fe42d3 100644
--- a/lib/Minz/Paginator.php
+++ b/lib/Minz/Paginator.php
@@ -64,7 +64,7 @@ class Minz_Paginator {
* @param Minz_Model $item l'élément à retrouver
* @return int|false la page à laquelle se trouve l’élément, false si non trouvé
*/
- public function pageByItem($item) {
+ public function pageByItem($item): int|false {
$i = 0;
do {
@@ -82,7 +82,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): int|false {
$i = 0;
do {
diff --git a/lib/Minz/Pdo.php b/lib/Minz/Pdo.php
index 33d84eb45..705c2d58c 100644
--- a/lib/Minz/Pdo.php
+++ b/lib/Minz/Pdo.php
@@ -37,58 +37,44 @@ abstract class Minz_Pdo extends PDO {
return $this->autoPrefix($statement);
}
- // PHP8+: PDO::lastInsertId(?string $name = null): string|false
/**
- * @param string|null $name
- * @return string|false
* @throws PDOException if the attribute `PDO::ATTR_ERRMODE` is set to `PDO::ERRMODE_EXCEPTION`
*/
#[\Override]
- #[\ReturnTypeWillChange]
- public function lastInsertId($name = null) {
+ public function lastInsertId(?string $name = null): string|false {
if ($name != null) {
$name = $this->preSql($name);
}
return parent::lastInsertId($name);
}
- // PHP8+: PDO::prepare(string $query, array $options = []): PDOStatement|false
/**
- * @param string $query
* @param array<int,string> $options
- * @return PDOStatement|false
* @throws PDOException if the attribute `PDO::ATTR_ERRMODE` is set to `PDO::ERRMODE_EXCEPTION`
* @phpstan-ignore method.childParameterType, throws.unusedType
*/
#[\Override]
- #[\ReturnTypeWillChange]
- public function prepare($query, $options = []) {
+ public function prepare(string $query, array $options = []): PDOStatement|false {
$query = $this->preSql($query);
return parent::prepare($query, $options);
}
- // PHP8+: PDO::exec(string $statement): int|false
/**
- * @param string $statement
- * @return int|false
* @throws PDOException if the attribute `PDO::ATTR_ERRMODE` is set to `PDO::ERRMODE_EXCEPTION`
* @phpstan-ignore throws.unusedType
*/
#[\Override]
- #[\ReturnTypeWillChange]
- public function exec($statement) {
+ public function exec(string $statement): int|false {
$statement = $this->preSql($statement);
return parent::exec($statement);
}
/**
- * @return PDOStatement|false
* @throws PDOException if the attribute `PDO::ATTR_ERRMODE` is set to `PDO::ERRMODE_EXCEPTION`
* @phpstan-ignore throws.unusedType
*/
#[\Override]
- #[\ReturnTypeWillChange]
- public function query(string $query, ?int $fetch_mode = null, ...$fetch_mode_args) {
+ public function query(string $query, ?int $fetch_mode = null, ...$fetch_mode_args): PDOStatement|false {
$query = $this->preSql($query);
return $fetch_mode === null ? parent::query($query) : parent::query($query, $fetch_mode, ...$fetch_mode_args);
}
diff --git a/lib/Minz/PdoMysql.php b/lib/Minz/PdoMysql.php
index 3f7a804a3..d7fca0168 100644
--- a/lib/Minz/PdoMysql.php
+++ b/lib/Minz/PdoMysql.php
@@ -22,13 +22,10 @@ class Minz_PdoMysql extends Minz_Pdo {
}
/**
- * @param string|null $name
- * @return string|false
* @throws PDOException if the attribute `PDO::ATTR_ERRMODE` is set to `PDO::ERRMODE_EXCEPTION`
*/
#[\Override]
- #[\ReturnTypeWillChange]
- public function lastInsertId($name = null) {
+ public function lastInsertId(?string $name = null): string|false {
return parent::lastInsertId(); //We discard the name, only used by PostgreSQL
}
}
diff --git a/lib/Minz/PdoSqlite.php b/lib/Minz/PdoSqlite.php
index 537b6cdc6..6aa83690c 100644
--- a/lib/Minz/PdoSqlite.php
+++ b/lib/Minz/PdoSqlite.php
@@ -22,13 +22,10 @@ class Minz_PdoSqlite extends Minz_Pdo {
}
/**
- * @param string|null $name
- * @return string|false
* @throws PDOException if the attribute `PDO::ATTR_ERRMODE` is set to `PDO::ERRMODE_EXCEPTION`
*/
#[\Override]
- #[\ReturnTypeWillChange]
- public function lastInsertId($name = null) {
+ public function lastInsertId(?string $name = null): string|false {
return parent::lastInsertId(); //We discard the name, only used by PostgreSQL
}
}
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index 1f15730fb..fcece464b 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -44,7 +44,7 @@ class Minz_Request {
* @return mixed value of the parameter
* @deprecated use typed versions instead
*/
- public static function param(string $key, $default = false, bool $specialchars = false) {
+ public static function param(string $key, mixed $default = false, bool $specialchars = false): mixed {
if (isset(self::$params[$key])) {
$p = self::$params[$key];
if (is_string($p) || is_array($p)) {
@@ -156,7 +156,7 @@ class Minz_Request {
}
/** @return array{c?:string,a?:string,params?:array<string,mixed>} */
- public static function originalRequest() {
+ public static function originalRequest(): array {
return self::$originalRequest;
}
diff --git a/lib/Minz/Session.php b/lib/Minz/Session.php
index 99b7fef45..c08ad688b 100644
--- a/lib/Minz/Session.php
+++ b/lib/Minz/Session.php
@@ -63,7 +63,7 @@ class Minz_Session {
* @return mixed|false the value of the session variable, false if doesn’t exist
* @deprecated Use typed versions instead
*/
- public static function param(string $p, $default = false) {
+ public static function param(string $p, $default = false): mixed {
return $_SESSION[$p] ?? $default;
}
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php
index 183fa48ca..a8dc889ee 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -255,9 +255,7 @@ class Minz_Translate {
/**
* Alias for Minz_Translate::t()
- * @param string $key
- * @param bool|float|int|string ...$args
*/
-function _t(string $key, ...$args): string {
+function _t(string $key, bool|float|int|string ...$args): string {
return Minz_Translate::t($key, ...$args);
}
diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php
index 310067382..3948414d8 100644
--- a/lib/Minz/Url.php
+++ b/lib/Minz/Url.php
@@ -13,11 +13,10 @@ class Minz_Url {
* $url['params'] = array of additional parameters
* or as a string
* @param string $encoding how to encode & (& ou &amp; pour html)
- * @param bool|string $absolute
* @return string Formatted URL
* @throws Minz_ConfigurationException
*/
- public static function display($url = [], string $encoding = 'html', $absolute = false): string {
+ public static function display($url = [], string $encoding = 'html', bool|string $absolute = false): string {
$isArray = is_array($url);
if ($isArray) {
@@ -160,13 +159,7 @@ class Minz_Url {
}
}
-/**
- * @param string $controller
- * @param string $action
- * @param string|int ...$args
- * @return string|false
- */
-function _url(string $controller, string $action, ...$args) {
+function _url(string $controller, string $action, int|string ...$args): string|false {
$nb_args = count($args);
if ($nb_args % 2 !== 0) {
diff --git a/lib/Minz/View.php b/lib/Minz/View.php
index 44b7378b6..f7dceef0a 100644
--- a/lib/Minz/View.php
+++ b/lib/Minz/View.php
@@ -232,8 +232,6 @@ class Minz_View {
/**
* Append a `<link>` element referencing stylesheet.
- * @param string $url
- * @param string $media
* @param bool $cond Conditional comment for IE, now deprecated and ignored @deprecated
*/
public static function appendStyle(string $url, string $media = 'all', bool $cond = false): void {
@@ -298,7 +296,6 @@ class Minz_View {
}
/**
* Prepend a `<script>` element.
- * @param string $url
* @param bool $cond Conditional comment for IE, now deprecated and ignored @deprecated
* @param bool $defer Use `defer` flag
* @param bool $async Use `async` flag
@@ -318,7 +315,6 @@ class Minz_View {
/**
* Append a `<script>` element.
- * @param string $url
* @param bool $cond Conditional comment for IE, now deprecated and ignored @deprecated
* @param bool $defer Use `defer` flag
* @param bool $async Use `async` flag
@@ -338,9 +334,8 @@ class Minz_View {
/**
* Management of parameters added to the view
- * @param mixed $value
*/
- public static function _param(string $key, $value): void {
+ public static function _param(string $key, mixed $value): void {
self::$params[$key] = $value;
}
diff --git a/lib/lib_date.php b/lib/lib_date.php
index ee8bf92f6..201d548ad 100644
--- a/lib/lib_date.php
+++ b/lib/lib_date.php
@@ -36,7 +36,7 @@ example('PT6M/');
example('PT7S/');
example('P1DT1H/');
-function example(string $dateInterval) {
+function example(string $dateInterval): void {
$dateIntervalArray = parseDateInterval($dateInterval);
echo $dateInterval, "\t=>\t",
$dateIntervalArray[0] == null ? 'null' : @date('c', $dateIntervalArray[0]), '/',
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index d066bd254..61055153c 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -5,37 +5,12 @@ if (version_compare(PHP_VERSION, FRESHRSS_MIN_PHP_VERSION, '<')) {
die(sprintf('FreshRSS error: FreshRSS requires PHP %s+!', FRESHRSS_MIN_PHP_VERSION));
}
-if (!function_exists('array_is_list')) {
- /**
- * Polyfill for PHP <8.1
- * https://php.net/array-is-list#127044
- * @param array<mixed> $array
- */
- function array_is_list(array $array): bool {
- $i = -1;
- foreach ($array as $k => $v) {
- ++$i;
- if ($k !== $i) {
- return false;
- }
- }
- return true;
- }
-}
-
if (!function_exists('mb_strcut')) {
function mb_strcut(string $str, int $start, ?int $length = null, string $encoding = 'UTF-8'): string {
return substr($str, $start, $length) ?: '';
}
}
-if (!function_exists('str_starts_with')) {
- /** Polyfill for PHP <8.0 */
- function str_starts_with(string $haystack, string $needle): bool {
- return strncmp($haystack, $needle, strlen($needle)) === 0;
- }
-}
-
if (!function_exists('syslog')) {
if (COPY_SYSLOG_TO_STDERR && !defined('STDERR')) {
define('STDERR', fopen('php://stderr', 'w'));
@@ -149,14 +124,7 @@ function idn_to_puny(string $url): string {
if (function_exists('idn_to_ascii')) {
$idn = parse_url($url, PHP_URL_HOST);
if (is_string($idn) && $idn != '') {
- // https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003
- if (defined('INTL_IDNA_VARIANT_UTS46')) {
- $puny = idn_to_ascii($idn, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46);
- } elseif (defined('INTL_IDNA_VARIANT_2003')) {
- $puny = idn_to_ascii($idn, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003);
- } else {
- $puny = idn_to_ascii($idn);
- }
+ $puny = idn_to_ascii($idn);
$pos = strpos($url, $idn);
if ($puny != false && $pos !== false) {
$url = substr_replace($url, $puny, $pos, strlen($idn));
@@ -166,10 +134,7 @@ function idn_to_puny(string $url): string {
return $url;
}
-/**
- * @return string|false
- */
-function checkUrl(string $url, bool $fixScheme = true) {
+function checkUrl(string $url, bool $fixScheme = true): string|false {
$url = trim($url);
if ($url == '') {
return '';
@@ -178,7 +143,7 @@ function checkUrl(string $url, bool $fixScheme = true) {
$url = 'https://' . ltrim($url, '/');
}
- $url = idn_to_puny($url); //PHP bug #53474 IDN
+ $url = idn_to_puny($url); // https://bugs.php.net/bug.php?id=53474
$urlRelaxed = str_replace('_', 'z', $url); //PHP discussion #64948 Underscore
if (is_string(filter_var($urlRelaxed, FILTER_VALIDATE_URL))) {
@@ -279,7 +244,7 @@ function html_only_entity_decode(?string $text): string {
* @param array<string,mixed>|string $log
* @return array<string,mixed>|string
*/
-function sensitive_log($log) {
+function sensitive_log($log): array|string {
if (is_array($log)) {
foreach ($log as $k => $v) {
if (in_array($k, ['api_key', 'Passwd', 'T'], true)) {