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
This commit is contained in:
Hypolite Petovan 2023-03-26 18:30:31 -04:00
parent f61fd93db0
commit 1a21f19f42
2 changed files with 9 additions and 2 deletions

View file

@ -22,6 +22,7 @@
namespace Friendica\Factory\Api\Mastodon; namespace Friendica\Factory\Api\Mastodon;
use Exception; use Exception;
use Friendica\Network\HTTPException;
use Friendica\Object\Api\Mastodon\Relationship as RelationshipEntity; use Friendica\Object\Api\Mastodon\Relationship as RelationshipEntity;
use Friendica\BaseFactory; use Friendica\BaseFactory;
use Friendica\Model\Contact; use Friendica\Model\Contact;
@ -41,9 +42,15 @@ class Relationship extends BaseFactory
$pcid = !empty($cdata['public']) ? $cdata['public'] : $contactId; $pcid = !empty($cdata['public']) ? $cdata['public'] : $contactId;
$cid = !empty($cdata['user']) ? $cdata['user'] : $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( return new RelationshipEntity(
$pcid, $pcid,
Contact::getById($cid), $contact,
Contact\User::isBlocked($cid, $uid), Contact\User::isBlocked($cid, $uid),
Contact\User::isIgnored($cid, $uid) Contact\User::isIgnored($cid, $uid)
); );

View file

@ -77,7 +77,7 @@ class Relationship extends BaseDataTransferObject
* @param bool $blocked "true" if user is blocked * @param bool $blocked "true" if user is blocked
* @param bool $muted "true" if user is muted * @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->id = (string)$contactId;
$this->following = false; $this->following = false;