diff options
| author | 2024-11-28 17:11:04 +0100 | |
|---|---|---|
| committer | 2024-11-28 17:11:04 +0100 | |
| commit | 15745d42b779ad14efde2932ab116f45eee39246 (patch) | |
| tree | 2528a36184d8152d4f2d90dc73df680f84bbe1d1 /app/Controllers | |
| parent | 604b186638276203c8495a3ee86da0cc240ab4d0 (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 'app/Controllers')
| -rw-r--r-- | app/Controllers/authController.php | 23 | ||||
| -rw-r--r-- | app/Controllers/configureController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/errorController.php | 4 | ||||
| -rwxr-xr-x | app/Controllers/feedController.php | 8 | ||||
| -rw-r--r-- | app/Controllers/importExportController.php | 51 | ||||
| -rw-r--r-- | app/Controllers/indexController.php | 4 | ||||
| -rw-r--r-- | app/Controllers/updateController.php | 7 |
7 files changed, 38 insertions, 61 deletions
diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php index ed021505d..700501371 100644 --- a/app/Controllers/authController.php +++ b/app/Controllers/authController.php @@ -72,27 +72,18 @@ class FreshRSS_auth_Controller extends FreshRSS_ActionController { $auth_type = FreshRSS_Context::systemConf()->auth_type; FreshRSS_Context::initUser(Minz_User::INTERNAL_USER, false); - switch ($auth_type) { - case 'form': - Minz_Request::forward(['c' => 'auth', 'a' => 'formLogin']); - break; - case 'http_auth': - Minz_Error::error(403, [ + match ($auth_type) { + 'form' => Minz_Request::forward(['c' => 'auth', 'a' => 'formLogin']), + 'http_auth' => Minz_Error::error(403, [ 'error' => [ _t('feedback.access.denied'), ' [HTTP Remote-User=' . htmlspecialchars(httpAuthUser(false), ENT_NOQUOTES, 'UTF-8') . ' ; Remote IP address=' . connectionRemoteAddress() . ']' ] - ], false); - break; - case 'none': - // It should not happen! - Minz_Error::error(404); - break; - default: - // TODO load plugin instead - Minz_Error::error(404); - } + ], false), + 'none' => Minz_Error::error(404), // It should not happen! + default => Minz_Error::error(404), // TODO load plugin instead + }; } /** diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index ebca7318d..b7cd01242 100644 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -515,7 +515,7 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController { FreshRSS_Context::userConf()->save(); invalidateHttpCache(); - Minz_Request::good(_t('feedback.conf.updated'), array('c' => 'configure', 'a' => 'privacy')); + Minz_Request::good(_t('feedback.conf.updated'), ['c' => 'configure', 'a' => 'privacy']); } FreshRSS_View::prependTitle(_t('conf.privacy') . ' ยท '); diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index 59e910bac..81ce8768d 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -12,7 +12,7 @@ class FreshRSS_error_Controller extends FreshRSS_ActionController { * * Parameters are passed by Minz_Session to have a proper url: * - error_code (default: 404) - * - error_logs (default: array()) + * - error_logs (default: []) */ public function indexAction(): void { $code_int = Minz_Session::paramInt('error_code') ?: 404; @@ -60,7 +60,7 @@ class FreshRSS_error_Controller extends FreshRSS_ActionController { break; } - $error_message = trim(implode($error_logs)); + $error_message = trim(implode('', $error_logs)); if ($error_message !== '') { $this->view->errorMessage = $error_message; } diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 89f3d65b1..60ee6d579 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -343,7 +343,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { // We try to get more information about the feed. $this->view->feed->load(true); $this->view->load_ok = true; - } catch (Exception $e) { + } catch (Exception) { $this->view->load_ok = false; } @@ -793,9 +793,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { private static function applyLabelActions(int $nbNewEntries): int|false { $tagDAO = FreshRSS_Factory::createTagDao(); $labels = FreshRSS_Context::labels(); - $labels = array_filter($labels, static function (FreshRSS_Tag $label) { - return !empty($label->filtersAction('label')); - }); + $labels = array_filter($labels, static fn(FreshRSS_Tag $label) => !empty($label->filtersAction('label'))); if (count($labels) <= 0) { return 0; } @@ -1203,7 +1201,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { $this->view->selectorSuccess = false; $this->view->htmlContent = $entry->content(false); } - } catch (Exception $e) { + } catch (Exception) { $this->view->fatalError = _t('feedback.sub.feed.selector_preview.http_error'); } } diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 53617ced7..afb1cbfec 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -35,18 +35,12 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { } private static function megabytes(string $size_str): float|int|string { - switch (substr($size_str, -1)) { - case 'M': - case 'm': - return (int)$size_str; - case 'K': - case 'k': - return (int)$size_str / 1024; - case 'G': - case 'g': - return (int)$size_str * 1024; - } - return $size_str; + return match (substr($size_str, -1)) { + 'M', 'm' => (int)$size_str, + 'K', 'k' => (int)$size_str / 1024, + 'G', 'g' => (int)$size_str * 1024, + default => $size_str, + }; } private static function minimumMemory(int|string $mb): void { @@ -190,7 +184,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { $error = false; try { $error = !$this->importFile($file['name'], $file['tmp_name']); - } catch (FreshRSS_ZipMissing_Exception $zme) { + } catch (FreshRSS_ZipMissing_Exception) { Minz_Request::bad( _t('feedback.import_export.no_zip_extension'), ['c' => 'importExport', 'a' => 'index'] @@ -215,17 +209,17 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { * That could be improved but should be enough for what we have to do. */ private static function guessFileType(string $filename): string { - if (substr_compare($filename, '.zip', -4) === 0) { + if (str_ends_with($filename, '.zip')) { return 'zip'; } elseif (stripos($filename, 'opml') !== false) { return 'opml'; - } elseif (substr_compare($filename, '.json', -5) === 0) { - if (strpos($filename, 'starred') !== false) { + } elseif (str_ends_with($filename, '.json')) { + if (str_contains($filename, 'starred')) { return 'json_starred'; } else { return 'json_feed'; } - } elseif (substr_compare($filename, '.xml', -4) === 0) { + } elseif (str_ends_with($filename, '.xml')) { if (preg_match('/Tiny|tt-?rss/i', $filename)) { return 'ttrss_starred'; } else { @@ -258,7 +252,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { $labels_cache = json_decode($item['label_cache'], true); if (is_array($labels_cache)) { foreach ($labels_cache as $label_cache) { - if (!empty($label_cache[1])) { + if (!empty($label_cache[1]) && is_string($label_cache[1])) { $item['categories'][] = 'user/-/label/' . trim($label_cache[1]); } } @@ -322,7 +316,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { } if (!empty($item['origin']['feedUrl'])) { $feedUrl = $item['origin']['feedUrl']; - } elseif (!empty($item['origin']['streamId']) && strpos($item['origin']['streamId'], 'feed/') === 0) { + } elseif (!empty($item['origin']['streamId']) && str_starts_with($item['origin']['streamId'], 'feed/')) { $feedUrl = substr($item['origin']['streamId'], 5); //Google Reader $item['origin']['feedUrl'] = $feedUrl; } elseif (!empty($item['origin']['htmlUrl'])) { @@ -588,7 +582,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { * - export_opml (default: false) * - export_starred (default: false) * - export_labelled (default: false) - * - export_feeds (default: array()) a list of feed ids + * - export_feeds (default: []) a list of feed ids */ public function exportAction(): void { if (!Minz_Request::isPost()) { @@ -683,17 +677,12 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { */ private static function filenameToContentType(string $filename): string { $filetype = self::guessFileType($filename); - switch ($filetype) { - case 'zip': - return 'application/zip'; - case 'opml': - return 'application/xml; charset=utf-8'; - case 'json_starred': - case 'json_feed': - return 'application/json; charset=utf-8'; - default: - return 'application/octet-stream'; - } + return match ($filetype) { + 'zip' => 'application/zip', + 'opml' => 'application/xml; charset=utf-8', + 'json_starred', 'json_feed' => 'application/json; charset=utf-8', + default => 'application/octet-stream', + }; } private const REGEX_SQLITE_FILENAME = '/^(?![.-])[0-9a-zA-Z_.@ #&()~\-]{1,128}\.sqlite$/'; diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 2ee72b7b7..a977386a3 100644 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -117,7 +117,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { try { FreshRSS_Context::updateUsingRequest(true); - } catch (FreshRSS_Context_Exception $e) { + } catch (FreshRSS_Context_Exception) { Minz_Error::error(404); } @@ -194,7 +194,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { try { FreshRSS_Context::updateUsingRequest(false); - } catch (FreshRSS_Context_Exception $e) { + } catch (FreshRSS_Context_Exception) { Minz_Error::error(404); } diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index e5bf276cd..c7623d0a4 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -89,7 +89,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { chdir($cwd); $line = implode('; ', $output); return $line == '' || - strpos($line, '[behind') !== false || strpos($line, '[ahead') !== false || strpos($line, '[gone') !== false; + str_contains($line, '[behind') || str_contains($line, '[ahead') || str_contains($line, '[gone'); } /** @return string|true */ @@ -169,8 +169,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { } private function is_release_channel_stable(string $currentVersion): bool { - return strpos($currentVersion, 'dev') === false && - strpos($currentVersion, 'edge') === false; + return !str_contains($currentVersion, 'dev') && !str_contains($currentVersion, 'edge'); } /* Check installation if there is a newer version. @@ -239,7 +238,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { $res_array = explode("\n", (string)$result, 2); $status = $res_array[0]; - if (strpos($status, 'UPDATE') !== 0) { + if (!str_starts_with($status, 'UPDATE')) { $this->view->message = [ 'status' => 'latest', 'body' => _t('feedback.update.none'), |
