From 15745d42b779ad14efde2932ab116f45eee39246 Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:11:04 +0100 Subject: 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 Co-authored-by: Alexandre Alapetite --- cli/CliOption.php | 7 +------ cli/create-user.php | 2 +- cli/do-install.php | 8 ++++---- cli/export-zip-for-user.php | 6 +++--- cli/i18n/I18nCompletionValidator.php | 11 ++++------- cli/i18n/I18nData.php | 11 +++-------- cli/i18n/I18nUsageValidator.php | 11 ++++------- cli/i18n/I18nValue.php | 4 ++-- cli/import-for-user.php | 2 +- cli/update-user.php | 2 +- cli/user-info.php | 4 ++-- 11 files changed, 26 insertions(+), 42 deletions(-) (limited to 'cli') diff --git a/cli/CliOption.php b/cli/CliOption.php index d0eace311..e92fbd804 100644 --- a/cli/CliOption.php +++ b/cli/CliOption.php @@ -5,18 +5,13 @@ final class CliOption { public const VALUE_NONE = 'none'; public const VALUE_REQUIRED = 'required'; public const VALUE_OPTIONAL = 'optional'; - - private string $longAlias; - private ?string $shortAlias; private string $valueTaken = self::VALUE_REQUIRED; /** @var array{type:string,isArray:bool} $types */ private array $types = ['type' => 'string', 'isArray' => false]; private string $optionalValueDefault = ''; private ?string $deprecatedAlias = null; - public function __construct(string $longAlias, ?string $shortAlias = null) { - $this->longAlias = $longAlias; - $this->shortAlias = $shortAlias; + public function __construct(private readonly string $longAlias, private readonly ?string $shortAlias = null) { } /** Sets this option to be treated as a flag. */ diff --git a/cli/create-user.php b/cli/create-user.php index ae560b49e..067ea2eff 100755 --- a/cli/create-user.php +++ b/cli/create-user.php @@ -79,7 +79,7 @@ $values = array_filter($values); $ok = FreshRSS_user_Controller::createUser( $username, - isset($cliOptions->email) ? $cliOptions->email : null, + $cliOptions->email ?? null, $cliOptions->password ?? '', $values, !isset($cliOptions->noDefaultFeeds) diff --git a/cli/do-install.php b/cli/do-install.php index 483a443d9..8591f2299 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -92,10 +92,10 @@ $dbValues = [ 'prefix' => $cliOptions->dbPrefix ?? null, ]; -$config = array( - 'salt' => generateSalt(), - 'db' => FreshRSS_Context::systemConf()->db, - ); +$config = [ + 'salt' => generateSalt(), + 'db' => FreshRSS_Context::systemConf()->db, +]; $customConfigPath = DATA_PATH . '/config.custom.php'; if (file_exists($customConfigPath)) { diff --git a/cli/export-zip-for-user.php b/cli/export-zip-for-user.php index 304acc392..e030274d2 100755 --- a/cli/export-zip-for-user.php +++ b/cli/export-zip-for-user.php @@ -33,11 +33,11 @@ $number_entries = $cliOptions->maxFeedEntries; $exported_files = []; // First, we generate the OPML file -list($filename, $content) = $export_service->generateOpml(); +[$filename, $content] = $export_service->generateOpml(); $exported_files[$filename] = $content; // Then, labelled and starred entries -list($filename, $content) = $export_service->generateStarredEntries('ST'); +[$filename, $content] = $export_service->generateStarredEntries('ST'); $exported_files[$filename] = $content; // And a list of entries based on the complete list of feeds @@ -46,7 +46,7 @@ $exported_files = array_merge($exported_files, $feeds_exported_files); // Finally, we compress all these files into a single Zip archive and we output // the content -list($filename, $content) = $export_service->zip($exported_files); +[$filename, $content] = $export_service->zip($exported_files); echo $content; invalidateHttpCache($username); diff --git a/cli/i18n/I18nCompletionValidator.php b/cli/i18n/I18nCompletionValidator.php index 2a42dc13f..28f8abed8 100644 --- a/cli/i18n/I18nCompletionValidator.php +++ b/cli/i18n/I18nCompletionValidator.php @@ -5,10 +5,6 @@ require_once __DIR__ . '/I18nValidatorInterface.php'; class I18nCompletionValidator implements I18nValidatorInterface { - /** @var array> */ - private array $reference; - /** @var array> */ - private array $language; private int $totalEntries = 0; private int $passEntries = 0; private string $result = ''; @@ -17,9 +13,10 @@ class I18nCompletionValidator implements I18nValidatorInterface { * @param array> $reference * @param array> $language */ - public function __construct(array $reference, array $language) { - $this->reference = $reference; - $this->language = $language; + public function __construct( + private readonly array $reference, + private array $language, + ) { } #[\Override] diff --git a/cli/i18n/I18nData.php b/cli/i18n/I18nData.php index 6d5730a08..6f841e947 100644 --- a/cli/i18n/I18nData.php +++ b/cli/i18n/I18nData.php @@ -5,13 +5,8 @@ class I18nData { public const REFERENCE_LANGUAGE = 'en'; - /** @var array>> */ - private array $data; - /** @param array>> $data */ - public function __construct(array $data) { - $this->data = $data; - + public function __construct(private array $data) { $this->addMissingKeysFromReference(); $this->removeExtraKeysFromOtherLanguages(); $this->processValueStates(); @@ -144,7 +139,7 @@ class I18nData { $keys = array_keys($this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)]); $parent = $this->getParentKey($key); - return array_values(array_filter($keys, static fn(string $element) => false !== strpos($element, $parent))); + return array_values(array_filter($keys, static fn(string $element) => str_contains($element, $parent))); } /** @@ -185,7 +180,7 @@ class I18nData { if ($element === $key) { return false; } - return false !== strpos($element, $key); + return str_contains($element, $key); })); return count($children) !== 0; diff --git a/cli/i18n/I18nUsageValidator.php b/cli/i18n/I18nUsageValidator.php index dd514236b..89c88d222 100644 --- a/cli/i18n/I18nUsageValidator.php +++ b/cli/i18n/I18nUsageValidator.php @@ -5,10 +5,6 @@ require_once __DIR__ . '/I18nValidatorInterface.php'; class I18nUsageValidator implements I18nValidatorInterface { - /** @var array */ - private array $code; - /** @var array> */ - private array $reference; private int $totalEntries = 0; private int $failedEntries = 0; private string $result = ''; @@ -17,9 +13,10 @@ class I18nUsageValidator implements I18nValidatorInterface { * @param array> $reference * @param array $code */ - public function __construct(array $reference, array $code) { - $this->code = $code; - $this->reference = $reference; + public function __construct( + private readonly array $reference, + private readonly array $code, + ) { } #[\Override] diff --git a/cli/i18n/I18nValue.php b/cli/i18n/I18nValue.php index aa2a670e1..ba6465062 100644 --- a/cli/i18n/I18nValue.php +++ b/cli/i18n/I18nValue.php @@ -1,7 +1,7 @@ importFile($filename, $filename, $username); -} catch (FreshRSS_ZipMissing_Exception $zme) { +} catch (FreshRSS_ZipMissing_Exception) { fail('FreshRSS error: Lacking php-zip extension!'); } catch (FreshRSS_Zip_Exception $ze) { fail('FreshRSS error: ZIP archive cannot be imported! Error code: ' . $ze->zipErrorCode()); diff --git a/cli/update-user.php b/cli/update-user.php index 553025d2b..946f296fa 100755 --- a/cli/update-user.php +++ b/cli/update-user.php @@ -70,7 +70,7 @@ $values = array_filter($values); $ok = FreshRSS_user_Controller::updateUser( $username, - isset($cliOptions->email) ? $cliOptions->email : null, + $cliOptions->email ?? null, $cliOptions->password ?? '', $values); diff --git a/cli/user-info.php b/cli/user-info.php index 6674ebc6b..5895d9b1d 100755 --- a/cli/user-info.php +++ b/cli/user-info.php @@ -69,7 +69,7 @@ foreach ($users as $username) { $nbFavorites = $entryDAO->countUnreadReadFavorites(); $feedList = $feedDAO->listFeedsIds(); - $data = array( + $data = [ 'default' => $username === FreshRSS_Context::systemConf()->default_user ? '*' : '', 'user' => $username, 'admin' => FreshRSS_Context::userConf()->is_admin ? '*' : '', @@ -84,7 +84,7 @@ foreach ($users as $username) { 'tags' => $tagDAO->count(), 'lang' => FreshRSS_Context::userConf()->language, 'mail_login' => FreshRSS_Context::userConf()->mail_login, - ); + ]; if (isset($cliOptions->humanReadable)) { //Human format $data['last_user_activity'] = date('c', $data['last_user_activity']); $data['database_size'] = format_bytes($data['database_size']); -- cgit v1.2.3