From 1a21f19f42619bd847c28790a266da6f31be8335 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 26 Mar 2023 18:30:31 -0400 Subject: [PATCH] Add exception throw when contact data isn't available in Factory/Api/Mastodon/Relationship - Address https://github.com/friendica/friendica/issues/12486#issuecomment-1445323023 - Remove default value to parameter which array keys are used in method body --- src/Factory/Api/Mastodon/Relationship.php | 9 ++++++++- src/Object/Api/Mastodon/Relationship.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Factory/Api/Mastodon/Relationship.php b/src/Factory/Api/Mastodon/Relationship.php index f1ca4a1f9e..8ae72ae9b2 100644 --- a/src/Factory/Api/Mastodon/Relationship.php +++ b/src/Factory/Api/Mastodon/Relationship.php @@ -22,6 +22,7 @@ namespace Friendica\Factory\Api\Mastodon; use Exception; +use Friendica\Network\HTTPException; use Friendica\Object\Api\Mastodon\Relationship as RelationshipEntity; use Friendica\BaseFactory; use Friendica\Model\Contact; @@ -41,9 +42,15 @@ class Relationship extends BaseFactory $pcid = !empty($cdata['public']) ? $cdata['public'] : $contactId; $cid = !empty($cdata['user']) ? $cdata['user'] : $contactId; + $contact = Contact::getById($cid); + if (!$contact) { + $this->logger->warning('Target contact not found', ['contactId' => $contactId, 'uid' => $uid, 'pcid' => $pcid, 'cid' => $cid]); + throw new HTTPException\NotFoundException('Contact not found.'); + } + return new RelationshipEntity( $pcid, - Contact::getById($cid), + $contact, Contact\User::isBlocked($cid, $uid), Contact\User::isIgnored($cid, $uid) ); diff --git a/src/Object/Api/Mastodon/Relationship.php b/src/Object/Api/Mastodon/Relationship.php index 42d0e73119..c042e81b5e 100644 --- a/src/Object/Api/Mastodon/Relationship.php +++ b/src/Object/Api/Mastodon/Relationship.php @@ -77,7 +77,7 @@ class Relationship extends BaseDataTransferObject * @param bool $blocked "true" if user is blocked * @param bool $muted "true" if user is muted */ - public function __construct(int $contactId, array $contactRecord = [], bool $blocked = false, bool $muted = false) + public function __construct(int $contactId, array $contactRecord, bool $blocked = false, bool $muted = false) { $this->id = (string)$contactId; $this->following = false;