summaryrefslogtreecommitdiff
path: root/cli
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 /cli
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 'cli')
-rw-r--r--cli/CliOption.php7
-rwxr-xr-xcli/create-user.php2
-rwxr-xr-xcli/do-install.php8
-rwxr-xr-xcli/export-zip-for-user.php6
-rw-r--r--cli/i18n/I18nCompletionValidator.php11
-rw-r--r--cli/i18n/I18nData.php11
-rw-r--r--cli/i18n/I18nUsageValidator.php11
-rw-r--r--cli/i18n/I18nValue.php4
-rwxr-xr-xcli/import-for-user.php2
-rwxr-xr-xcli/update-user.php2
-rwxr-xr-xcli/user-info.php4
11 files changed, 26 insertions, 42 deletions
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<string,array<string,I18nValue>> */
- private array $reference;
- /** @var array<string,array<string,I18nValue>> */
- private array $language;
private int $totalEntries = 0;
private int $passEntries = 0;
private string $result = '';
@@ -17,9 +13,10 @@ class I18nCompletionValidator implements I18nValidatorInterface {
* @param array<string,array<string,I18nValue>> $reference
* @param array<string,array<string,I18nValue>> $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<string,array<string,array<string,I18nValue>>> */
- private array $data;
-
/** @param array<string,array<string,array<string,I18nValue>>> $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<string> */
- private array $code;
- /** @var array<string,array<string,I18nValue>> */
- private array $reference;
private int $totalEntries = 0;
private int $failedEntries = 0;
private string $result = '';
@@ -17,9 +13,10 @@ class I18nUsageValidator implements I18nValidatorInterface {
* @param array<string,array<string,I18nValue>> $reference
* @param array<string> $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 @@
<?php
declare(strict_types=1);
-class I18nValue {
+class I18nValue implements \Stringable {
private const STATE_DIRTY = 'dirty';
public const STATE_IGNORE = 'ignore';
private const STATE_TODO = 'todo';
@@ -11,7 +11,7 @@ class I18nValue {
self::STATE_TODO,
];
- private string $value;
+ private readonly string $value;
private ?string $state = null;
/** @param I18nValue|string $data */
diff --git a/cli/import-for-user.php b/cli/import-for-user.php
index 4c4db8405..17dc9750e 100755
--- a/cli/import-for-user.php
+++ b/cli/import-for-user.php
@@ -34,7 +34,7 @@ $importController = new FreshRSS_importExport_Controller();
$ok = false;
try {
$ok = $importController->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']);