From eaed3945d1aad0bbd81878f90705e636c1915de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Fri, 29 Jul 2022 00:36:07 +0200 Subject: [PATCH] Changed: - used `$this->getRequestValue($request, 'foo', )` instead of `$request['foo'] ?? ` - fixed wrong variable naming - changed double-quotes to single - see https://github.com/friendica/friendica/issues/11631#issuecomment-1196410497 --- src/Model/Contact.php | 2 +- src/Module/Api/Friendica/DirectMessages/Search.php | 2 +- src/Module/Api/Friendica/Group/Delete.php | 2 +- src/Module/Api/Friendica/Notification/Seen.php | 2 +- src/Module/Api/GNUSocial/Statusnet/Conversation.php | 2 +- src/Module/Api/Twitter/Account/RateLimitStatus.php | 8 ++++---- src/Module/Api/Twitter/DirectMessages/Conversation.php | 2 +- src/Module/Api/Twitter/DirectMessages/Destroy.php | 5 ++--- src/Module/Api/Twitter/DirectMessages/NewDM.php | 4 ++-- src/Module/Api/Twitter/DirectMessagesEndpoint.php | 4 ++-- src/Module/Api/Twitter/Favorites/Create.php | 2 +- src/Module/Api/Twitter/Favorites/Destroy.php | 2 +- src/Module/Api/Twitter/Followers/Ids.php | 2 +- src/Module/Api/Twitter/Followers/Lists.php | 2 +- src/Module/Api/Twitter/Friends/Ids.php | 2 +- src/Module/Api/Twitter/Friends/Lists.php | 2 +- src/Module/Api/Twitter/Friendships/Destroy.php | 2 +- src/Module/Api/Twitter/Friendships/Show.php | 5 ++--- src/Module/Api/Twitter/Statuses/UserTimeline.php | 2 +- src/Module/Api/Twitter/Users/Show.php | 2 +- src/Module/Feed.php | 2 +- 21 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index a6bb882e86..3d38005455 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -2969,7 +2969,7 @@ class Contact $cdata = self::getPublicAndUserContactID($contact['id'], $contact['uid']); - DI::notification()->deleteForUserByVerb($contact['uid'], Activity::FOLLOW, ['actor-id' => $cdata['public']]); + DI::notification()->deleteForUserByVerb($contact['uid'], Activity::FOLLOW, ['actor-id' => $contact['public']]); } /** diff --git a/src/Module/Api/Friendica/DirectMessages/Search.php b/src/Module/Api/Friendica/DirectMessages/Search.php index 67f8193f25..26d8efaf78 100644 --- a/src/Module/Api/Friendica/DirectMessages/Search.php +++ b/src/Module/Api/Friendica/DirectMessages/Search.php @@ -77,7 +77,7 @@ class Search extends BaseApi } else { $ret = []; foreach ($mails as $mail) { - $ret[] = $this->directMessage->createFromMailId($mail['id'], $uid, $request['getText'] ?? ''); + $ret[] = $this->directMessage->createFromMailId($mail['id'], $uid, $this->getRequestValue($request, 'getText', '')); } $success = ['success' => true, 'search_results' => $ret]; } diff --git a/src/Module/Api/Friendica/Group/Delete.php b/src/Module/Api/Friendica/Group/Delete.php index d48e9a4f9d..d263bbbd74 100644 --- a/src/Module/Api/Friendica/Group/Delete.php +++ b/src/Module/Api/Friendica/Group/Delete.php @@ -44,7 +44,7 @@ class Delete extends BaseApi // params // error if no gid specified - if ($request['gid'] == 0 || $request['name'] == "") { + if ($request['gid'] == 0 || $request['name'] == '') { throw new BadRequestException('gid or name not specified'); } diff --git a/src/Module/Api/Friendica/Notification/Seen.php b/src/Module/Api/Friendica/Notification/Seen.php index 7a52a124df..00015d90bc 100644 --- a/src/Module/Api/Friendica/Notification/Seen.php +++ b/src/Module/Api/Friendica/Notification/Seen.php @@ -47,7 +47,7 @@ class Seen extends BaseApi throw new BadRequestException('Invalid argument count'); } - $id = intval($request['id'] ?? 0); + $id = intval($this->getRequestValue($request, 'id', 0)); $include_entities = $this->getRequestValue($request, 'include_entities', false); diff --git a/src/Module/Api/GNUSocial/Statusnet/Conversation.php b/src/Module/Api/GNUSocial/Statusnet/Conversation.php index 65ef9654b8..98d1de14d0 100644 --- a/src/Module/Api/GNUSocial/Statusnet/Conversation.php +++ b/src/Module/Api/GNUSocial/Statusnet/Conversation.php @@ -50,7 +50,7 @@ class Conversation extends BaseApi $start = max(0, ($page - 1) * $count); if ($id == 0) { - $id = $request['id'] ?? 0; + $id = $this->getRequestValue($request, 'id', 0); } Logger::info(BaseApi::LOG_PREFIX . '{subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $id]); diff --git a/src/Module/Api/Twitter/Account/RateLimitStatus.php b/src/Module/Api/Twitter/Account/RateLimitStatus.php index c5f052b394..739ed04b5d 100644 --- a/src/Module/Api/Twitter/Account/RateLimitStatus.php +++ b/src/Module/Api/Twitter/Account/RateLimitStatus.php @@ -34,13 +34,13 @@ class RateLimitStatus extends BaseApi if (($this->parameters['extension'] ?? '') == 'xml') { $hash = [ 'remaining-hits' => '150', - '@attributes' => ["type" => "integer"], + '@attributes' => ['type' => 'integer'], 'hourly-limit' => '150', - '@attributes2' => ["type" => "integer"], + '@attributes2' => ['type' => 'integer'], 'reset-time' => DateTimeFormat::utc('now + 1 hour', DateTimeFormat::ATOM), - '@attributes3' => ["type" => "datetime"], + '@attributes3' => ['type' => 'datetime'], 'reset_time_in_seconds' => strtotime('now + 1 hour'), - '@attributes4' => ["type" => "integer"], + '@attributes4' => ['type' => 'integer'], ]; } else { $hash = [ diff --git a/src/Module/Api/Twitter/DirectMessages/Conversation.php b/src/Module/Api/Twitter/DirectMessages/Conversation.php index ebd4b6bbc4..808189c24d 100644 --- a/src/Module/Api/Twitter/DirectMessages/Conversation.php +++ b/src/Module/Api/Twitter/DirectMessages/Conversation.php @@ -34,6 +34,6 @@ class Conversation extends DirectMessagesEndpoint BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); $uid = BaseApi::getCurrentUserID(); - $this->getMessages($request, $uid, ["`parent-uri` = ?", $request['uri'] ?? '']); + $this->getMessages($request, $uid, ["`parent-uri` = ?", $this->getRequestValue($request, 'uri', '')]); } } diff --git a/src/Module/Api/Twitter/DirectMessages/Destroy.php b/src/Module/Api/Twitter/DirectMessages/Destroy.php index 9de0982364..2b95f7a6b6 100644 --- a/src/Module/Api/Twitter/DirectMessages/Destroy.php +++ b/src/Module/Api/Twitter/DirectMessages/Destroy.php @@ -55,9 +55,8 @@ class Destroy extends BaseApi $id = $this->getRequestValue($request, 'id', 0); $id = $this->getRequestValue($this->parameters, 'id', $id); - $verbose = $this->getRequestValue($request, 'friendica_verbose', false); - - $parenturi = $request['friendica_parenturi'] ?? ''; + $verbose = $this->getRequestValue($request, 'friendica_verbose', false); + $parenturi = $this->getRequestValue($request, 'friendica_parenturi', ''); // error if no id or parenturi specified (for clients posting parent-uri as well) if ($verbose && $id == 0 && $parenturi == "") { diff --git a/src/Module/Api/Twitter/DirectMessages/NewDM.php b/src/Module/Api/Twitter/DirectMessages/NewDM.php index 7ac82533e8..1eaa601953 100644 --- a/src/Module/Api/Twitter/DirectMessages/NewDM.php +++ b/src/Module/Api/Twitter/DirectMessages/NewDM.php @@ -63,7 +63,7 @@ class NewDM extends BaseApi return; } - $cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, 0); + $cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), 0); if (empty($cid)) { throw new NotFoundException('Recipient not found'); } @@ -86,7 +86,7 @@ class NewDM extends BaseApi $id = Mail::send($cdata['user'], $request['text'], $sub, $replyto); if ($id > -1) { - $ret = $this->directMessage->createFromMailId($id, $uid, $request['getText'] ?? ''); + $ret = $this->directMessage->createFromMailId($id, $uid, $this->getRequestValue($request, 'getText', '')); } else { $ret = ['error' => $id]; } diff --git a/src/Module/Api/Twitter/DirectMessagesEndpoint.php b/src/Module/Api/Twitter/DirectMessagesEndpoint.php index 28b867889f..5505c6c44c 100644 --- a/src/Module/Api/Twitter/DirectMessagesEndpoint.php +++ b/src/Module/Api/Twitter/DirectMessagesEndpoint.php @@ -84,7 +84,7 @@ abstract class DirectMessagesEndpoint extends BaseApi $params['order'] = ['id']; } - $cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, 0); + $cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), 0); if (!empty($cid)) { $cdata = Contact::getPublicAndUserContactID($cid, $uid); if (!empty($cdata['user'])) { @@ -109,7 +109,7 @@ abstract class DirectMessagesEndpoint extends BaseApi $ret = []; foreach ($ids as $id) { - $ret[] = $this->directMessage->createFromMailId($id, $uid, $request['getText'] ?? ''); + $ret[] = $this->directMessage->createFromMailId($id, $uid, $this->getRequestValue($request, 'getText', '')); } self::setLinkHeader(); diff --git a/src/Module/Api/Twitter/Favorites/Create.php b/src/Module/Api/Twitter/Favorites/Create.php index 6544fe470c..c81b5af873 100644 --- a/src/Module/Api/Twitter/Favorites/Create.php +++ b/src/Module/Api/Twitter/Favorites/Create.php @@ -37,7 +37,7 @@ class Create extends BaseApi self::checkAllowedScope(self::SCOPE_WRITE); $uid = self::getCurrentUserID(); - $id = $request['id'] ?? 0; + $id = $this->getRequestValue($request, 'id', 0); if (empty($id)) { throw new BadRequestException('Item id not specified'); diff --git a/src/Module/Api/Twitter/Favorites/Destroy.php b/src/Module/Api/Twitter/Favorites/Destroy.php index 0d3046afb1..c03064e79a 100644 --- a/src/Module/Api/Twitter/Favorites/Destroy.php +++ b/src/Module/Api/Twitter/Favorites/Destroy.php @@ -37,7 +37,7 @@ class Destroy extends BaseApi self::checkAllowedScope(self::SCOPE_WRITE); $uid = self::getCurrentUserID(); - $id = $request['id'] ?? 0; + $id = $this->getRequestValue($request, 'id', 0); if (empty($id)) { throw new BadRequestException('Item id not specified'); diff --git a/src/Module/Api/Twitter/Followers/Ids.php b/src/Module/Api/Twitter/Followers/Ids.php index df7120ab62..6acf7c8311 100644 --- a/src/Module/Api/Twitter/Followers/Ids.php +++ b/src/Module/Api/Twitter/Followers/Ids.php @@ -37,7 +37,7 @@ class Ids extends ContactEndpoint $uid = BaseApi::getCurrentUserID(); // Expected value for user_id parameter: public/user contact id - $cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid); + $cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), $uid); $cursor = $this->getRequestValue($request, 'cursor', -1); $stringify_ids = $this->getRequestValue($request, 'stringify_ids', false); $count = $this->getRequestValue($request, 'count', self::DEFAULT_COUNT, 1, self::MAX_COUNT); diff --git a/src/Module/Api/Twitter/Followers/Lists.php b/src/Module/Api/Twitter/Followers/Lists.php index 0e9a2aa82a..fbae33652f 100644 --- a/src/Module/Api/Twitter/Followers/Lists.php +++ b/src/Module/Api/Twitter/Followers/Lists.php @@ -37,7 +37,7 @@ class Lists extends ContactEndpoint $uid = BaseApi::getCurrentUserID(); // Expected value for user_id parameter: public/user contact id - $cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid); + $cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), $uid); $cursor = $this->getRequestValue($request, 'cursor', -1); $skip_status = $this->getRequestValue($request, 'skip_status', false); $include_user_entities = $this->getRequestValue($request, 'include_user_entities', false); diff --git a/src/Module/Api/Twitter/Friends/Ids.php b/src/Module/Api/Twitter/Friends/Ids.php index b5b571a9f0..a46be8deb9 100644 --- a/src/Module/Api/Twitter/Friends/Ids.php +++ b/src/Module/Api/Twitter/Friends/Ids.php @@ -37,7 +37,7 @@ class Ids extends ContactEndpoint $uid = BaseApi::getCurrentUserID(); // Expected value for user_id parameter: public/user contact id - $cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid); + $cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), $uid); $cursor = $this->getRequestValue($request, 'cursor', -1); $stringify_ids = $this->getRequestValue($request, 'stringify_ids', false); $count = $this->getRequestValue($request, 'count', self::DEFAULT_COUNT, 1, self::MAX_COUNT); diff --git a/src/Module/Api/Twitter/Friends/Lists.php b/src/Module/Api/Twitter/Friends/Lists.php index 750ba6db61..304f19db9e 100644 --- a/src/Module/Api/Twitter/Friends/Lists.php +++ b/src/Module/Api/Twitter/Friends/Lists.php @@ -37,7 +37,7 @@ class Lists extends ContactEndpoint $uid = BaseApi::getCurrentUserID(); // Expected value for user_id parameter: public/user contact id - $cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid); + $cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), $uid); $cursor = $this->getRequestValue($request, 'cursor', -1); $skip_status = $this->getRequestValue($request, 'skip_status', false); $include_user_entities = $this->getRequestValue($request, 'include_user_entities', false); diff --git a/src/Module/Api/Twitter/Friendships/Destroy.php b/src/Module/Api/Twitter/Friendships/Destroy.php index b730f06636..d324fc6be4 100644 --- a/src/Module/Api/Twitter/Friendships/Destroy.php +++ b/src/Module/Api/Twitter/Friendships/Destroy.php @@ -63,7 +63,7 @@ class Destroy extends ContactEndpoint throw new HTTPException\NotFoundException('Error Processing Request'); } - $contact_id = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, 0); + $contact_id = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), 0); if (empty($contact_id)) { Logger::notice(BaseApi::LOG_PREFIX . 'No user_id specified', ['module' => 'api', 'action' => 'friendships_destroy']); diff --git a/src/Module/Api/Twitter/Friendships/Show.php b/src/Module/Api/Twitter/Friendships/Show.php index 66605e7265..c05dc09023 100644 --- a/src/Module/Api/Twitter/Friendships/Show.php +++ b/src/Module/Api/Twitter/Friendships/Show.php @@ -38,9 +38,8 @@ class Show extends ContactEndpoint self::checkAllowedScope(self::SCOPE_READ); $uid = BaseApi::getCurrentUserID(); - $source_cid = BaseApi::getContactIDForSearchterm($request['source_screen_name'] ?? '', '', $request['source_id'] ?? 0, $uid); - - $target_cid = BaseApi::getContactIDForSearchterm($request['target_screen_name'] ?? '', '', $request['target_id'] ?? 0, $uid); + $source_cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'source_screen_name', ''), '', $this->getRequestValue($request, 'source_id', 0), $uid); + $target_cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'target_screen_name', ''), '', $this->getRequestValue($request, 'target_id', 0), $uid); $source = Contact::getById($source_cid); if (empty($source)) { diff --git a/src/Module/Api/Twitter/Statuses/UserTimeline.php b/src/Module/Api/Twitter/Statuses/UserTimeline.php index 05aa079624..a6616636ca 100644 --- a/src/Module/Api/Twitter/Statuses/UserTimeline.php +++ b/src/Module/Api/Twitter/Statuses/UserTimeline.php @@ -42,7 +42,7 @@ class UserTimeline extends BaseApi Logger::info('api_statuses_user_timeline', ['api_user' => $uid, '_REQUEST' => $request]); - $cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid); + $cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), $uid); $count = $this->getRequestValue($request, 'count', 20, 1, 100); $page = $this->getRequestValue($request, 'page', 1, 1); $since_id = $this->getRequestValue($request, 'since_id', 0, 0); diff --git a/src/Module/Api/Twitter/Users/Show.php b/src/Module/Api/Twitter/Users/Show.php index e6bd24d27b..27510b9387 100644 --- a/src/Module/Api/Twitter/Users/Show.php +++ b/src/Module/Api/Twitter/Users/Show.php @@ -38,7 +38,7 @@ class Show extends BaseApi $uid = BaseApi::getCurrentUserID(); if (empty($this->parameters['id'])) { - $cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid); + $cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), $uid); } else { $cid = (int)$this->parameters['id']; } diff --git a/src/Module/Feed.php b/src/Module/Feed.php index 9acde7bb30..4c942cd762 100644 --- a/src/Module/Feed.php +++ b/src/Module/Feed.php @@ -45,7 +45,7 @@ class Feed extends BaseModule { protected function rawContent(array $request = []) { - $last_update = $request['last_update'] ?? ''; + $last_update = $this->getRequestValue($request, 'last_update', ''); $nocache = !empty($request['nocache']) && local_user(); $type = null;