diff options
| author | 2024-09-06 09:06:46 +0200 | |
|---|---|---|
| committer | 2024-09-06 09:06:46 +0200 | |
| commit | a81656c3ed5b8fe0f31794a4fbe0d1a907fca8e8 (patch) | |
| tree | 8bf49bd876aaebc985a9fb1214863190a799cbee /p/api | |
| parent | 8f7c3473a76809efc88814253722c76f0cc8eb04 (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 'p/api')
| -rw-r--r-- | p/api/fever.php | 22 | ||||
| -rw-r--r-- | p/api/greader.php | 80 |
2 files changed, 32 insertions, 70 deletions
diff --git a/p/api/fever.php b/p/api/fever.php index 77d778305..5ddfba269 100644 --- a/p/api/fever.php +++ b/p/api/fever.php @@ -426,33 +426,29 @@ final class FeverAPI /** * @param numeric-string $id - * @return int|false */ - private function setItemAsRead(string $id) { + private function setItemAsRead(string $id): int|false { return $this->entryDAO->markRead($id, true); } /** * @param numeric-string $id - * @return int|false */ - private function setItemAsUnread(string $id) { + private function setItemAsUnread(string $id): int|false { return $this->entryDAO->markRead($id, false); } /** * @param numeric-string $id - * @return int|false */ - private function setItemAsSaved(string $id) { + private function setItemAsSaved(string $id): int|false { return $this->entryDAO->markFavorite($id, true); } /** * @param numeric-string $id - * @return int|false */ - private function setItemAsUnsaved(string $id) { + private function setItemAsUnsaved(string $id): int|false { return $this->entryDAO->markFavorite($id, false); } @@ -538,18 +534,12 @@ final class FeverAPI return $beforeTimestamp == 0 ? '0' : $beforeTimestamp . '000000'; } - /** - * @return int|false - */ - private function setFeedAsRead(int $id, int $before) { + private function setFeedAsRead(int $id, int $before): int|false { $before = $this->convertBeforeToId($before); return $this->entryDAO->markReadFeed($id, $before); } - /** - * @return int|false - */ - private function setGroupAsRead(int $id, int $before) { + private function setGroupAsRead(int $id, int $before): int|false { $before = $this->convertBeforeToId($before); // special case to mark all items as read diff --git a/p/api/greader.php b/p/api/greader.php index 8a492a213..1fd821307 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -112,14 +112,12 @@ function debugInfo(): string { final class GReaderAPI { - /** @return never */ - private static function noContent() { + private static function noContent(): never { header('HTTP/1.1 204 No Content'); exit(); } - /** @return never */ - private static function badRequest() { + private static function badRequest(): never { Minz_Log::warning(__METHOD__, API_LOG); Minz_Log::debug(__METHOD__ . ' ' . debugInfo(), API_LOG); header('HTTP/1.1 400 Bad Request'); @@ -127,8 +125,7 @@ final class GReaderAPI { die('Bad Request!'); } - /** @return never */ - private static function unauthorized() { + private static function unauthorized(): never { Minz_Log::warning(__METHOD__, API_LOG); Minz_Log::debug(__METHOD__ . ' ' . debugInfo(), API_LOG); header('HTTP/1.1 401 Unauthorized'); @@ -137,8 +134,7 @@ final class GReaderAPI { die('Unauthorized!'); } - /** @return never */ - private static function internalServerError() { + private static function internalServerError(): never { Minz_Log::warning(__METHOD__, API_LOG); Minz_Log::debug(__METHOD__ . ' ' . debugInfo(), API_LOG); header('HTTP/1.1 500 Internal Server Error'); @@ -146,8 +142,7 @@ final class GReaderAPI { die('Internal Server Error!'); } - /** @return never */ - private static function notImplemented() { + private static function notImplemented(): never { Minz_Log::warning(__METHOD__, API_LOG); Minz_Log::debug(__METHOD__ . ' ' . debugInfo(), API_LOG); header('HTTP/1.1 501 Not Implemented'); @@ -155,8 +150,7 @@ final class GReaderAPI { die('Not Implemented!'); } - /** @return never */ - private static function serviceUnavailable() { + private static function serviceUnavailable(): never { Minz_Log::warning(__METHOD__, API_LOG); Minz_Log::debug(__METHOD__ . ' ' . debugInfo(), API_LOG); header('HTTP/1.1 503 Service Unavailable'); @@ -164,8 +158,7 @@ final class GReaderAPI { die('Service Unavailable!'); } - /** @return never */ - private static function checkCompatibility() { + private static function checkCompatibility(): never { Minz_Log::warning(__METHOD__, API_LOG); Minz_Log::debug(__METHOD__ . ' ' . debugInfo(), API_LOG); header('Content-Type: text/plain; charset=UTF-8'); @@ -211,8 +204,7 @@ final class GReaderAPI { return ''; } - /** @return never */ - private static function clientLogin(string $email, string $pass) { + private static function clientLogin(string $email, string $pass): never { //https://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html if (FreshRSS_user_Controller::checkUsername($email)) { FreshRSS_Context::initUser($email); @@ -237,10 +229,7 @@ final class GReaderAPI { } } - /** - * @return never - */ - private static function token(?FreshRSS_UserConfiguration $conf) { + private static function token(?FreshRSS_UserConfiguration $conf): never { //http://blog.martindoms.com/2009/08/15/using-the-google-reader-api-part-1/ //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php $user = Minz_User::name(); @@ -271,8 +260,7 @@ final class GReaderAPI { self::unauthorized(); } - /** @return never */ - private static function userInfo() { + private static function userInfo(): never { //https://github.com/theoldreader/api#user-info if (!FreshRSS_Context::hasUserConf()) { self::unauthorized(); @@ -286,8 +274,7 @@ final class GReaderAPI { ), JSON_OPTIONS)); } - /** @return never */ - private static function tagList() { + private static function tagList(): never { header('Content-Type: application/json; charset=UTF-8'); $tags = array( @@ -320,8 +307,7 @@ final class GReaderAPI { exit(); } - /** @return never */ - private static function subscriptionExport() { + private static function subscriptionExport(): never { $user = Minz_User::name() ?? Minz_User::INTERNAL_USER; $export_service = new FreshRSS_Export_Service($user); [$filename, $content] = $export_service->generateOpml(); @@ -331,8 +317,7 @@ final class GReaderAPI { exit(); } - /** @return never */ - private static function subscriptionImport(string $opml) { + private static function subscriptionImport(string $opml): never { $user = Minz_User::name() ?? Minz_User::INTERNAL_USER; $importService = new FreshRSS_Import_Service($user); $importService->importOpml($opml); @@ -345,8 +330,7 @@ final class GReaderAPI { } } - /** @return never */ - private static function subscriptionList() { + private static function subscriptionList(): never { if (!FreshRSS_Context::hasSystemConf()) { self::internalServerError(); } @@ -384,9 +368,8 @@ final class GReaderAPI { /** * @param array<string> $streamNames * @param array<string> $titles - * @return never */ - private static function subscriptionEdit(array $streamNames, array $titles, string $action, string $add = '', string $remove = '') { + private static function subscriptionEdit(array $streamNames, array $titles, string $action, string $add = '', string $remove = ''): never { //https://github.com/mihaip/google-reader-api/blob/master/wiki/ApiSubscriptionEdit.wiki switch ($action) { case 'subscribe': @@ -474,8 +457,7 @@ final class GReaderAPI { exit('OK'); } - /** @return never */ - private static function quickadd(string $url) { + private static function quickadd(string $url): never { try { $url = htmlspecialchars($url, ENT_COMPAT, 'UTF-8'); if (str_starts_with($url, 'feed/')) { @@ -497,8 +479,7 @@ final class GReaderAPI { } } - /** @return never */ - private static function unreadCount() { + private static function unreadCount(): never { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count header('Content-Type: application/json; charset=UTF-8'); @@ -592,10 +573,9 @@ final class GReaderAPI { /** * @param 'A'|'c'|'f'|'s' $type - * @param string|int $streamId * @phpstan-return array{'A'|'c'|'f'|'s'|'t',int,int,FreshRSS_BooleanSearch} */ - private static function streamContentsFilters(string $type, $streamId, + private static function streamContentsFilters(string $type, int|string $streamId, string $filter_target, string $exclude_target, int $start_time, int $stop_time): array { switch ($type) { case 'f': //feed @@ -670,9 +650,8 @@ final class GReaderAPI { return array($type, $streamId, $state, $searches); } - /** @return never */ private static function streamContents(string $path, string $include_target, int $start_time, int $stop_time, int $count, - string $order, string $filter_target, string $exclude_target, string $continuation) { + string $order, string $filter_target, string $exclude_target, string $continuation): never { //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed header('Content-Type: application/json; charset=UTF-8'); @@ -728,9 +707,8 @@ final class GReaderAPI { exit(); } - /** @return never */ private static function streamContentsItemsIds(string $streamId, int $start_time, int $stop_time, int $count, - string $order, string $filter_target, string $exclude_target, string $continuation) { + string $order, string $filter_target, string $exclude_target, string $continuation): never { //http://code.google.com/p/google-reader-api/wiki/ApiStreamItemsIds //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed @@ -790,9 +768,8 @@ final class GReaderAPI { /** * @param array<string> $e_ids - * @return never */ - private static function streamContentsItems(array $e_ids, string $order) { + private static function streamContentsItems(array $e_ids, string $order): never { header('Content-Type: application/json; charset=UTF-8'); foreach ($e_ids as $i => $e_id) { @@ -822,9 +799,8 @@ final class GReaderAPI { /** * @param array<string> $e_ids - * @return never */ - private static function editTag(array $e_ids, string $a, string $r): void { + private static function editTag(array $e_ids, string $a, string $r): never { foreach ($e_ids as $i => $e_id) { if (!ctype_digit($e_id) || $e_id[0] === '0') { $e_ids[$i] = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/' @@ -898,8 +874,7 @@ final class GReaderAPI { exit('OK'); } - /** @return never */ - private static function renameTag(string $s, string $dest) { + private static function renameTag(string $s, string $dest): never { if ($s != '' && strpos($s, 'user/-/label/') === 0 && $dest != '' && strpos($dest, 'user/-/label/') === 0) { $s = substr($s, 13); @@ -926,8 +901,7 @@ final class GReaderAPI { self::badRequest(); } - /** @return never */ - private static function disableTag(string $s) { + private static function disableTag(string $s): never { if ($s != '' && strpos($s, 'user/-/label/') === 0) { $s = substr($s, 13); $s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8'); @@ -954,9 +928,8 @@ final class GReaderAPI { /** * @param numeric-string $olderThanId - * @return never */ - private static function markAllAsRead(string $streamId, string $olderThanId) { + private static function markAllAsRead(string $streamId, string $olderThanId): never { $entryDAO = FreshRSS_Factory::createEntryDao(); if (strpos($streamId, 'feed/') === 0) { $f_id = basename($streamId); @@ -989,8 +962,7 @@ final class GReaderAPI { exit('OK'); } - /** @return never */ - public static function parse() { + public static function parse(): never { global $ORIGINAL_INPUT; header('Access-Control-Allow-Headers: Authorization'); |
