aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> 2024-11-28 17:11:04 +0100
committerGravatar GitHub <noreply@github.com> 2024-11-28 17:11:04 +0100
commit15745d42b779ad14efde2932ab116f45eee39246 (patch)
tree2528a36184d8152d4f2d90dc73df680f84bbe1d1 /lib
parent604b186638276203c8495a3ee86da0cc240ab4d0 (diff)
Upgrade code to php 8.1 (#6748)
* revert Fix code indentation Fix code Upgrade code to php 8.1 * fix remarques * code review * code review * code review * Apply suggestions from code review * code review * Fixes * Many remainging updates of array syntax * Lost case 'reading-list' * Uneeded PHPDoc --------- Co-authored-by: Luc Sanchez <l.sanchez-prestataire@alptis.fr> Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Configuration.php4
-rw-r--r--lib/Minz/ExtensionManager.php98
-rw-r--r--lib/Minz/ModelArray.php2
-rw-r--r--lib/Minz/PdoPgsql.php2
-rw-r--r--lib/Minz/Request.php2
-rw-r--r--lib/Minz/Session.php2
-rw-r--r--lib/Minz/Translate.php16
-rw-r--r--lib/favicons.php6
-rw-r--r--lib/lib_date.php4
-rw-r--r--lib/lib_install.php6
-rw-r--r--lib/lib_rss.php26
11 files changed, 83 insertions, 85 deletions
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index 40a5851a9..b2742e249 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -18,7 +18,7 @@ class Minz_Configuration {
* The list of configurations.
* @var array<string,static>
*/
- private static array $config_list = array();
+ private static array $config_list = [];
/**
* Add a new configuration to the list of configuration.
@@ -132,7 +132,7 @@ class Minz_Configuration {
* @param Minz_ConfigurationSetterInterface|null $configuration_setter the setter to call when modifying data.
*/
public function _configurationSetter(?Minz_ConfigurationSetterInterface $configuration_setter): void {
- if (is_callable(array($configuration_setter, 'handle'))) {
+ if (is_callable([$configuration_setter, 'handle'])) {
$this->configuration_setter = $configuration_setter;
}
}
diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php
index 976dddb82..90f005d29 100644
--- a/lib/Minz/ExtensionManager.php
+++ b/lib/Minz/ExtensionManager.php
@@ -22,74 +22,74 @@ final class Minz_ExtensionManager {
* @var array<string,array{'list':array<callable>,'signature':'NoneToNone'|'NoneToString'|'OneToOne'|'PassArguments'}>
*/
private static array $hook_list = [
- 'check_url_before_add' => array( // function($url) -> Url | null
- 'list' => array(),
+ 'check_url_before_add' => [ // function($url) -> Url | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
+ ],
'entries_favorite' => [ // function(array $ids, bool $is_favorite): void
'list' => [],
'signature' => 'PassArguments',
],
- 'entry_auto_read' => array( // function(FreshRSS_Entry $entry, string $why): void
- 'list' => array(),
+ 'entry_auto_read' => [ // function(FreshRSS_Entry $entry, string $why): void
+ 'list' => [],
'signature' => 'PassArguments',
- ),
- 'entry_auto_unread' => array( // function(FreshRSS_Entry $entry, string $why): void
- 'list' => array(),
+ ],
+ 'entry_auto_unread' => [ // function(FreshRSS_Entry $entry, string $why): void
+ 'list' => [],
'signature' => 'PassArguments',
- ),
- 'entry_before_display' => array( // function($entry) -> Entry | null
- 'list' => array(),
+ ],
+ 'entry_before_display' => [ // function($entry) -> Entry | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'entry_before_insert' => array( // function($entry) -> Entry | null
- 'list' => array(),
+ ],
+ 'entry_before_insert' => [ // function($entry) -> Entry | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'feed_before_actualize' => array( // function($feed) -> Feed | null
- 'list' => array(),
+ ],
+ 'feed_before_actualize' => [ // function($feed) -> Feed | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'feed_before_insert' => array( // function($feed) -> Feed | null
- 'list' => array(),
+ ],
+ 'feed_before_insert' => [ // function($feed) -> Feed | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'freshrss_init' => array( // function() -> none
- 'list' => array(),
+ ],
+ 'freshrss_init' => [ // function() -> none
+ 'list' => [],
'signature' => 'NoneToNone',
- ),
- 'freshrss_user_maintenance' => array( // function() -> none
- 'list' => array(),
+ ],
+ 'freshrss_user_maintenance' => [ // function() -> none
+ 'list' => [],
'signature' => 'NoneToNone',
- ),
- 'js_vars' => array( // function($vars = array) -> array | null
- 'list' => array(),
+ ],
+ 'js_vars' => [ // function($vars = array) -> array | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'menu_admin_entry' => array( // function() -> string
- 'list' => array(),
+ ],
+ 'menu_admin_entry' => [ // function() -> string
+ 'list' => [],
'signature' => 'NoneToString',
- ),
- 'menu_configuration_entry' => array( // function() -> string
- 'list' => array(),
+ ],
+ 'menu_configuration_entry' => [ // function() -> string
+ 'list' => [],
'signature' => 'NoneToString',
- ),
- 'menu_other_entry' => array( // function() -> string
- 'list' => array(),
+ ],
+ 'menu_other_entry' => [ // function() -> string
+ 'list' => [],
'signature' => 'NoneToString',
- ),
- 'nav_menu' => array( // function() -> string
- 'list' => array(),
+ ],
+ 'nav_menu' => [ // function() -> string
+ 'list' => [],
'signature' => 'NoneToString',
- ),
- 'nav_reading_modes' => array( // function($readingModes = array) -> array | null
- 'list' => array(),
+ ],
+ 'nav_reading_modes' => [ // function($readingModes = array) -> array | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'post_update' => array( // function(none) -> none
- 'list' => array(),
+ ],
+ 'post_update' => [ // function(none) -> none
+ 'list' => [],
'signature' => 'NoneToNone',
- ),
+ ],
'simplepie_after_init' => [ // function(\SimplePie\SimplePie $simplePie, FreshRSS_Feed $feed, bool $result): void
'list' => [],
'signature' => 'PassArguments',
@@ -187,7 +187,7 @@ final class Minz_ExtensionManager {
* @return bool true if the array is valid, false else.
*/
private static function isValidMetadata(array $meta): bool {
- $valid_chars = array('_');
+ $valid_chars = ['_'];
return !(empty($meta['name']) || empty($meta['entrypoint']) || !ctype_alnum(str_replace($valid_chars, '', $meta['entrypoint'])));
}
diff --git a/lib/Minz/ModelArray.php b/lib/Minz/ModelArray.php
index f12e23567..5a1d286cd 100644
--- a/lib/Minz/ModelArray.php
+++ b/lib/Minz/ModelArray.php
@@ -41,7 +41,7 @@ class Minz_ModelArray {
if ($data === false) {
throw new Minz_PermissionDeniedException($this->filename);
} elseif (!is_array($data)) {
- $data = array();
+ $data = [];
}
return $data;
}
diff --git a/lib/Minz/PdoPgsql.php b/lib/Minz/PdoPgsql.php
index d075c396f..a43d7addf 100644
--- a/lib/Minz/PdoPgsql.php
+++ b/lib/Minz/PdoPgsql.php
@@ -24,6 +24,6 @@ class Minz_PdoPgsql extends Minz_Pdo {
#[\Override]
protected function preSql(string $statement): string {
$statement = parent::preSql($statement);
- return str_replace(array('`', ' LIKE '), array('"', ' ILIKE '), $statement);
+ return str_replace(['`', ' LIKE '], ['"', ' ILIKE '], $statement);
}
}
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index b4d4549a9..bddb5a276 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -490,6 +490,6 @@ class Minz_Request {
if (preg_match_all('/(^|,)\s*(?P<lang>[^;,]+)/', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', $matches) > 0) {
return $matches['lang'];
}
- return array('en');
+ return ['en'];
}
}
diff --git a/lib/Minz/Session.php b/lib/Minz/Session.php
index c08ad688b..9977e62f6 100644
--- a/lib/Minz/Session.php
+++ b/lib/Minz/Session.php
@@ -164,7 +164,7 @@ class Minz_Session {
if (!self::$volatile) {
session_destroy();
}
- $_SESSION = array();
+ $_SESSION = [];
if (!$force) {
self::_param('language', $language);
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php
index a8dc889ee..08b3c91e8 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -40,8 +40,8 @@ class Minz_Translate {
*/
public static function init(string $lang_name = ''): void {
self::$lang_name = $lang_name;
- self::$lang_files = array();
- self::$translates = array();
+ self::$lang_files = [];
+ self::$translates = [];
self::registerPath(APP_PATH . '/i18n');
foreach (self::$path_list as $path) {
self::loadLang($path);
@@ -54,8 +54,8 @@ class Minz_Translate {
*/
public static function reset(string $lang_name): void {
self::$lang_name = $lang_name;
- self::$lang_files = array();
- self::$translates = array();
+ self::$lang_files = [];
+ self::$translates = [];
foreach (self::$path_list as $path) {
self::loadLang($path);
}
@@ -66,7 +66,7 @@ class Minz_Translate {
* @return array<string> containing langs found in different registered paths.
*/
public static function availableLanguages(): array {
- $list_langs = array();
+ $list_langs = [];
self::registerPath(APP_PATH . '/i18n');
@@ -75,7 +75,7 @@ class Minz_Translate {
if (is_array($scan)) {
$path_langs = array_values(array_diff(
$scan,
- array('..', '.')
+ ['..', '.']
));
$list_langs = array_merge($list_langs, $path_langs);
}
@@ -146,7 +146,7 @@ class Minz_Translate {
foreach ($list_i18n_files as $i18n_filename) {
$i18n_key = basename($i18n_filename, '.php');
if (!isset(self::$lang_files[$i18n_key])) {
- self::$lang_files[$i18n_key] = array();
+ self::$lang_files[$i18n_key] = [];
}
self::$lang_files[$i18n_key][] = $lang_path . '/' . $i18n_filename;
self::$translates[$i18n_key] = null;
@@ -164,7 +164,7 @@ class Minz_Translate {
return false;
}
- self::$translates[$key] = array();
+ self::$translates[$key] = [];
foreach (self::$lang_files[$key] as $lang_pathname) {
$i18n_array = include($lang_pathname);
diff --git a/lib/favicons.php b/lib/favicons.php
index be83b8066..5df3682b8 100644
--- a/lib/favicons.php
+++ b/lib/favicons.php
@@ -103,7 +103,7 @@ function searchFavicon(string &$url): string {
}
$iri = $href->get_iri();
- $favicon = downloadHttp($iri, array(CURLOPT_REFERER => $url));
+ $favicon = downloadHttp($iri, [CURLOPT_REFERER => $url]);
if (isImgMime($favicon)) {
return $favicon;
}
@@ -122,9 +122,7 @@ function download_favicon(string $url, string $dest): bool {
}
if ($favicon == '') {
$link = $rootUrl . 'favicon.ico';
- $favicon = downloadHttp($link, array(
- CURLOPT_REFERER => $url,
- ));
+ $favicon = downloadHttp($link, [CURLOPT_REFERER => $url]);
if (!isImgMime($favicon)) {
$favicon = '';
}
diff --git a/lib/lib_date.php b/lib/lib_date.php
index 201d548ad..9d4bcaa07 100644
--- a/lib/lib_date.php
+++ b/lib/lib_date.php
@@ -67,7 +67,7 @@ function _dateCeiling(string $isoDate): string {
/** @phpstan-return ($isoDate is null ? null : ($isoDate is '' ? null : string)) */
function _noDelimit(?string $isoDate): ?string {
- return $isoDate === null || $isoDate === '' ? null : str_replace(array('-', ':'), '', $isoDate); //FIXME: Bug with negative time zone
+ return $isoDate === null || $isoDate === '' ? null : str_replace(['-', ':'], '', $isoDate); //FIXME: Bug with negative time zone
}
function _dateRelative(?string $d1, ?string $d2): ?string {
@@ -139,5 +139,5 @@ function parseDateInterval(string $dateInterval): array {
$min = false;
}
}
- return array($min, $max);
+ return [$min, $max];
}
diff --git a/lib/lib_install.php b/lib/lib_install.php
index d8ccd7624..e78de565b 100644
--- a/lib/lib_install.php
+++ b/lib/lib_install.php
@@ -47,7 +47,7 @@ function checkRequirements(string $dbType = ''): array {
$users = is_dir(USERS_PATH) && touch(USERS_PATH . '/index.html');
$favicons = is_dir(DATA_PATH) && touch(DATA_PATH . '/favicons/index.html');
- return array(
+ return [
'php' => $php ? 'ok' : 'ko',
'curl' => $curl ? 'ok' : 'ko',
'pdo-mysql' => $pdo_mysql ? 'ok' : 'ko',
@@ -68,8 +68,8 @@ function checkRequirements(string $dbType = ''): array {
'favicons' => $favicons ? 'ok' : 'ko',
'message' => $message ?: '',
'all' => $php && $curl && $pdo && $pcre && $ctype && $dom && $xml &&
- $data && $cache && $tmp && $users && $favicons && $message == '' ? 'ok' : 'ko'
- );
+ $data && $cache && $tmp && $users && $favicons && $message == '' ? 'ok' : 'ko',
+ ];
}
function generateSalt(): string {
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 32139d8c8..8eb89c578 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -178,14 +178,14 @@ function escapeToUnicodeAlternative(string $text, bool $extended = true): string
$text = htmlspecialchars_decode($text, ENT_QUOTES);
//Problematic characters
- $problem = array('&', '<', '>');
+ $problem = ['&', '<', '>'];
//Use their fullwidth Unicode form instead:
- $replace = array('&', '<', '>');
+ $replace = ['&', '<', '>'];
// https://raw.githubusercontent.com/mihaip/google-reader-api/master/wiki/StreamId.wiki
if ($extended) {
- $problem += array("'", '"', '^', '?', '\\', '/', ',', ';');
- $replace += array("’", '"', '^', '?', '\', '/', ',', ';');
+ $problem += ["'", '"', '^', '?', '\\', '/', ',', ';'];
+ $replace += ["’", '"', '^', '?', '\', '/', ',', ';'];
}
return trim(str_replace($problem, $replace, $text));
@@ -202,10 +202,10 @@ function format_number($n, int $precision = 0): string {
function format_bytes(int $bytes, int $precision = 2, string $system = 'IEC'): string {
if ($system === 'IEC') {
$base = 1024;
- $units = array('B', 'KiB', 'MiB', 'GiB', 'TiB');
+ $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
} elseif ($system === 'SI') {
$base = 1000;
- $units = array('B', 'KB', 'MB', 'GB', 'TB');
+ $units = ['B', 'KB', 'MB', 'GB', 'TB'];
} else {
return format_number($bytes, $precision);
}
@@ -506,7 +506,7 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
- CURLOPT_HTTPHEADER => array('Accept: ' . $accept),
+ CURLOPT_HTTPHEADER => ['Accept: ' . $accept],
CURLOPT_USERAGENT => FRESHRSS_USERAGENT,
CURLOPT_CONNECTTIMEOUT => $feed_timeout > 0 ? $feed_timeout : $limits['timeout'],
CURLOPT_TIMEOUT => $feed_timeout > 0 ? $feed_timeout : $limits['timeout'],
@@ -609,7 +609,7 @@ function invalidateHttpCache(string $username = ''): bool {
* @return array<string>
*/
function listUsers(): array {
- $final_list = array();
+ $final_list = [];
$base_path = join_path(DATA_PATH, 'users');
$dir_list = array_values(array_diff(
scandir($base_path) ?: [],
@@ -784,7 +784,7 @@ function check_install_php(): array {
$pdo_mysql = extension_loaded('pdo_mysql');
$pdo_pgsql = extension_loaded('pdo_pgsql');
$pdo_sqlite = extension_loaded('pdo_sqlite');
- return array(
+ return [
'php' => version_compare(PHP_VERSION, FRESHRSS_MIN_PHP_VERSION) >= 0,
'curl' => extension_loaded('curl'),
'pdo' => $pdo_mysql || $pdo_sqlite || $pdo_pgsql,
@@ -795,7 +795,7 @@ function check_install_php(): array {
'json' => extension_loaded('json'),
'mbstring' => extension_loaded('mbstring'),
'zip' => extension_loaded('zip'),
- );
+ ];
}
/**
@@ -818,7 +818,7 @@ function check_install_files(): array {
* @return array<string,bool> of tested values.
*/
function check_install_database(): array {
- $status = array(
+ $status = [
'connection' => true,
'tables' => false,
'categories' => false,
@@ -827,7 +827,7 @@ function check_install_database(): array {
'entrytmp' => false,
'tag' => false,
'entrytag' => false,
- );
+ ];
try {
$dbDAO = FreshRSS_Factory::createDatabaseDAO();
@@ -876,7 +876,7 @@ function recursive_unlink(string $dir): bool {
* @return array<int,array<string,string|int>> without queries where $get is appearing.
*/
function remove_query_by_get(string $get, array $queries): array {
- $final_queries = array();
+ $final_queries = [];
foreach ($queries as $key => $query) {
if (empty($query['get']) || $query['get'] !== $get) {
$final_queries[$key] = $query;