From 8a5560ec8f1474b8f250abc7db61a0048f1a88e2 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 12 May 2021 12:40:45 +0000 Subject: [PATCH] Simplified null check --- src/Module/Api/Mastodon/Apps.php | 8 ++++---- src/Module/Api/Mastodon/Directory.php | 2 +- src/Module/Api/Mastodon/Notifications.php | 2 +- src/Module/BaseApi.php | 6 +++--- src/Module/OAuth/Authorize.php | 2 +- src/Module/OAuth/Token.php | 6 +++--- src/Module/Security/Login.php | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Module/Api/Mastodon/Apps.php b/src/Module/Api/Mastodon/Apps.php index 0f0837c78..7b13b1701 100644 --- a/src/Module/Api/Mastodon/Apps.php +++ b/src/Module/Api/Mastodon/Apps.php @@ -37,10 +37,10 @@ class Apps extends BaseApi */ public static function post(array $parameters = []) { - $name = !isset($_REQUEST['client_name']) ? '' : $_REQUEST['client_name']; - $redirect = !isset($_REQUEST['redirect_uris']) ? '' : $_REQUEST['redirect_uris']; - $scopes = !isset($_REQUEST['scopes']) ? '' : $_REQUEST['scopes']; - $website = !isset($_REQUEST['website']) ? '' : $_REQUEST['website']; + $name = $_REQUEST['client_name'] ?? ''; + $redirect = $_REQUEST['redirect_uris'] ?? ''; + $scopes = $_REQUEST['scopes'] ?? ''; + $website = $_REQUEST['website'] ?? ''; if (empty($name) || empty($redirect)) { DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Missing parameters')); diff --git a/src/Module/Api/Mastodon/Directory.php b/src/Module/Api/Mastodon/Directory.php index 70046642c..f2849f7f8 100644 --- a/src/Module/Api/Mastodon/Directory.php +++ b/src/Module/Api/Mastodon/Directory.php @@ -44,7 +44,7 @@ class Directory extends BaseApi { $offset = (int)!isset($_REQUEST['offset']) ? 0 : $_REQUEST['offset']; $limit = (int)!isset($_REQUEST['limit']) ? 40 : $_REQUEST['limit']; - $order = !isset($_REQUEST['order']) ? 'active' : $_REQUEST['order']; + $order = $_REQUEST['order'] ?? 'active'; $local = (bool)!isset($_REQUEST['local']) ? false : ($_REQUEST['local'] == 'true'); Logger::info('directory', ['offset' => $offset, 'limit' => $limit, 'order' => $order, 'local' => $local]); diff --git a/src/Module/Api/Mastodon/Notifications.php b/src/Module/Api/Mastodon/Notifications.php index a10ebf5d5..8252de7c2 100644 --- a/src/Module/Api/Mastodon/Notifications.php +++ b/src/Module/Api/Mastodon/Notifications.php @@ -63,7 +63,7 @@ class Notifications extends BaseApi $limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit']; // Array of types to exclude (follow, favourite, reblog, mention, poll, follow_request) - $exclude_types = !isset($_REQUEST['exclude_types']) ? [] : $_REQUEST['exclude_types']; + $exclude_types = $_REQUEST['exclude_types'] ?? []; // Return only notifications received from this account $account_id = (int)!isset($_REQUEST['account_id']) ? 0 : $_REQUEST['account_id']; diff --git a/src/Module/BaseApi.php b/src/Module/BaseApi.php index 27c4fee10..b4f228a6e 100644 --- a/src/Module/BaseApi.php +++ b/src/Module/BaseApi.php @@ -210,9 +210,9 @@ class BaseApi extends BaseModule */ public static function getApplication() { - $redirect_uri = !isset($_REQUEST['redirect_uri']) ? '' : $_REQUEST['redirect_uri']; - $client_id = !isset($_REQUEST['client_id']) ? '' : $_REQUEST['client_id']; - $client_secret = !isset($_REQUEST['client_secret']) ? '' : $_REQUEST['client_secret']; + $redirect_uri = $_REQUEST['redirect_uri'] ?? ''; + $client_id = $_REQUEST['client_id'] ?? ''; + $client_secret = $_REQUEST['client_secret'] ?? ''; if ((empty($redirect_uri) && empty($client_secret)) || empty($client_id)) { Logger::warning('Incomplete request', ['request' => $_REQUEST]); diff --git a/src/Module/OAuth/Authorize.php b/src/Module/OAuth/Authorize.php index a93fc0038..c9bf7b687 100644 --- a/src/Module/OAuth/Authorize.php +++ b/src/Module/OAuth/Authorize.php @@ -36,7 +36,7 @@ class Authorize extends BaseApi */ public static function rawContent(array $parameters = []) { - $response_type = !isset($_REQUEST['response_type']) ? '' : $_REQUEST['response_type']; + $response_type = $_REQUEST['response_type'] ?? ''; if ($response_type != 'code') { Logger::warning('Wrong or missing response type', ['response_type' => $response_type]); DI::mstdnError()->RecordNotFound(); diff --git a/src/Module/OAuth/Token.php b/src/Module/OAuth/Token.php index 164623482..17f2e2b82 100644 --- a/src/Module/OAuth/Token.php +++ b/src/Module/OAuth/Token.php @@ -34,9 +34,9 @@ class Token extends BaseApi { public static function post(array $parameters = []) { - $client_secret = !isset($_REQUEST['client_secret']) ? '' : $_REQUEST['client_secret']; - $code = !isset($_REQUEST['code']) ? '' : $_REQUEST['code']; - $grant_type = !isset($_REQUEST['grant_type']) ? '' : $_REQUEST['grant_type']; + $client_secret = $_REQUEST['client_secret'] ?? ''; + $code = $_REQUEST['code'] ?? ''; + $grant_type = $_REQUEST['grant_type'] ?? ''; if ($grant_type != 'authorization_code') { Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]); diff --git a/src/Module/Security/Login.php b/src/Module/Security/Login.php index 80a966220..1d45b6c9d 100644 --- a/src/Module/Security/Login.php +++ b/src/Module/Security/Login.php @@ -36,7 +36,7 @@ class Login extends BaseModule { public static function content(array $parameters = []) { - $return_path = !isset($_REQUEST['return_path']) ? '' : $_REQUEST['return_path']; + $return_path = $_REQUEST['return_path'] ?? '' ; if (local_user()) { DI::baseUrl()->redirect($return_path);