From 06e3051ad1943de85fa1061cfd7399b002ca143f Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 3 Dec 2024 21:44:35 +0000 Subject: [PATCH] Fix errors in Factory namespace --- src/BaseEntity.php | 21 ++++++++++---- src/DI.php | 4 +-- src/Factory/Api/Mastodon/Card.php | 5 ++-- src/Factory/Api/Mastodon/Notification.php | 11 +++---- src/Factory/Api/Mastodon/Status.php | 23 ++++++++------- src/Factory/Api/Mastodon/StatusSource.php | 3 +- src/Factory/Api/Mastodon/Subscription.php | 7 ++--- src/Factory/Api/Twitter/Status.php | 29 ++++++++++--------- .../Notifications/Entity/Notification.php | 22 +++++++------- src/Object/Api/Mastodon/Status/Counts.php | 2 ++ 10 files changed, 71 insertions(+), 56 deletions(-) diff --git a/src/BaseEntity.php b/src/BaseEntity.php index 6f61872548..09a2562c8e 100644 --- a/src/BaseEntity.php +++ b/src/BaseEntity.php @@ -7,7 +7,7 @@ namespace Friendica; -use Friendica\Network\HTTPException; +use Friendica\Network\HTTPException\InternalServerErrorException; /** * The Entity classes directly inheriting from this abstract class are meant to represent a single business entity. @@ -23,18 +23,29 @@ use Friendica\Network\HTTPException; * * Since these objects aren't meant to be using any dependency, including logging, unit tests can and must be * written for each and all of their methods + * + * @property-read int $id + * @property-read int $uid + * @property-read string $verb + * @property-read int $type + * @property-read int $actorId + * @property-read int $targetUriId + * @property-read int $parentUriId + * @property-read \DateTime $created + * @property-read bool $seen + * @property-read bool $dismissed */ abstract class BaseEntity extends BaseDataTransferObject { /** * @param string $name * @return mixed - * @throws HTTPException\InternalServerErrorException + * @throws InternalServerErrorException */ public function __get(string $name) { if (!property_exists($this, $name)) { - throw new HTTPException\InternalServerErrorException('Unknown property ' . $name . ' in Entity ' . static::class); + throw new InternalServerErrorException('Unknown property ' . $name . ' in Entity ' . static::class); } return $this->$name; @@ -43,12 +54,12 @@ abstract class BaseEntity extends BaseDataTransferObject /** * @param mixed $name * @return bool - * @throws HTTPException\InternalServerErrorException + * @throws InternalServerErrorException */ public function __isset($name): bool { if (!property_exists($this, $name)) { - throw new HTTPException\InternalServerErrorException('Unknown property ' . $name . ' of type ' . gettype($name) . ' in Entity ' . static::class); + throw new InternalServerErrorException('Unknown property ' . $name . ' of type ' . gettype($name) . ' in Entity ' . static::class); } return !empty($this->$name); diff --git a/src/DI.php b/src/DI.php index 8e422a129e..56a94d9b97 100644 --- a/src/DI.php +++ b/src/DI.php @@ -525,7 +525,7 @@ abstract class DI // /** - * @return Contact\FriendSuggest\Repository\FriendSuggest; + * @return Contact\FriendSuggest\Repository\FriendSuggest */ public static function fsuggest() { @@ -533,7 +533,7 @@ abstract class DI } /** - * @return Contact\FriendSuggest\Factory\FriendSuggest; + * @return Contact\FriendSuggest\Factory\FriendSuggest */ public static function fsuggestFactory() { diff --git a/src/Factory/Api/Mastodon/Card.php b/src/Factory/Api/Mastodon/Card.php index 1a517dea20..32388b4776 100644 --- a/src/Factory/Api/Mastodon/Card.php +++ b/src/Factory/Api/Mastodon/Card.php @@ -8,10 +8,8 @@ namespace Friendica\Factory\Api\Mastodon; use Friendica\BaseFactory; -use Friendica\Content\Text\BBCode; use Friendica\Model\Post; use Friendica\Network\HTTPException; -use Friendica\Util\Strings; class Card extends BaseFactory { @@ -21,7 +19,8 @@ class Card extends BaseFactory * * @return \Friendica\Object\Api\Mastodon\Card * @throws HTTPException\InternalServerErrorException - * @throws \ImagickException*@throws \Exception + * @throws \ImagickException + * @throws \Exception */ public function createFromUriId(int $uriId, array $history = []): \Friendica\Object\Api\Mastodon\Card { diff --git a/src/Factory/Api/Mastodon/Notification.php b/src/Factory/Api/Mastodon/Notification.php index 452cc18cea..4b78a90b8a 100644 --- a/src/Factory/Api/Mastodon/Notification.php +++ b/src/Factory/Api/Mastodon/Notification.php @@ -9,7 +9,7 @@ namespace Friendica\Factory\Api\Mastodon; use Friendica\BaseFactory; use Friendica\Model\Contact; -use Friendica\Navigation\Notifications; +use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity; use Friendica\Navigation\Notifications\Exception\UnexpectedNotificationTypeException; use Friendica\Object\Api\Mastodon\Notification as MstdnNotification; use Friendica\Protocol\Activity; @@ -32,16 +32,17 @@ class Notification extends BaseFactory } /** - * @param Notifications\Entity\Notification $Notification - * @param bool $display_quote Display quoted posts + * @param NotificationEntity $Notification + * @param bool $display_quotes Display quoted posts * * @return MstdnNotification * @throws UnexpectedNotificationTypeException */ - public function createFromNotification(Notifications\Entity\Notification $Notification, bool $display_quotes): MstdnNotification + public function createFromNotification(NotificationEntity $Notification, bool $display_quotes): MstdnNotification { $type = self::getType($Notification); - if (empty($type)) { + + if ($type === '') { throw new UnexpectedNotificationTypeException(); } diff --git a/src/Factory/Api/Mastodon/Status.php b/src/Factory/Api/Mastodon/Status.php index 3e55b427b5..8cf9f3d8e7 100644 --- a/src/Factory/Api/Mastodon/Status.php +++ b/src/Factory/Api/Mastodon/Status.php @@ -20,7 +20,8 @@ use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\Verb; -use Friendica\Network\HTTPException; +use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\NotFoundException; use Friendica\Object\Api\Mastodon\Status\FriendicaDeliveryData; use Friendica\Object\Api\Mastodon\Status\FriendicaExtension; use Friendica\Object\Api\Mastodon\Status\FriendicaVisibility; @@ -87,8 +88,8 @@ class Status extends BaseFactory * @param bool $in_reply_status Add an "in_reply_status" element * * @return \Friendica\Object\Api\Mastodon\Status - * @throws HTTPException\InternalServerErrorException - * @throws ImagickException|HTTPException\NotFoundException + * @throws InternalServerErrorException + * @throws ImagickException|NotFoundException */ public function createFromUriId(int $uriId, int $uid = 0, bool $display_quote = false, bool $reblog = true, bool $in_reply_status = true): \Friendica\Object\Api\Mastodon\Status { @@ -101,7 +102,7 @@ class Status extends BaseFactory if ($mail) { return $this->createFromMailId($mail['id']); } - throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.')); + throw new NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.')); } $activity_fields = ['uri-id', 'thr-parent-id', 'uri', 'author-id', 'author-uri-id', 'author-link', 'app', 'created', 'network', 'parent-author-id', 'private']; @@ -113,7 +114,7 @@ class Status extends BaseFactory $activity = $item; $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]); if (!$item) { - throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.')); + throw new NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.')); } foreach ($activity_fields as $field) { $item[$field] = $activity[$field]; @@ -202,7 +203,7 @@ class Status extends BaseFactory $sensitive = (bool)$item['sensitive']; $network = ContactSelector::networkToName($item['network']); - $sitename = ''; + $sitename = ''; $platform = ''; $version = ''; @@ -211,7 +212,7 @@ class Status extends BaseFactory if (!empty($gserver)) { $platform = ucfirst($gserver['platform']); $version = $gserver['version']; - $sitename = $gserver['site_name']; + $sitename = $gserver['site_name']; } } @@ -370,17 +371,17 @@ class Status extends BaseFactory } /** - * @param int $uriId id of the mail + * @param int $id id of the mail * * @return \Friendica\Object\Api\Mastodon\Status - * @throws HTTPException\InternalServerErrorException - * @throws ImagickException|HTTPException\NotFoundException + * @throws InternalServerErrorException + * @throws ImagickException|NotFoundException */ public function createFromMailId(int $id): \Friendica\Object\Api\Mastodon\Status { $item = ActivityPub\Transmitter::getItemArrayFromMail($id, true); if (empty($item)) { - throw new HTTPException\NotFoundException('Mail record not found with id: ' . $id); + throw new NotFoundException('Mail record not found with id: ' . $id); } $account = $this->mstdnAccountFactory->createFromContactId($item['author-id']); diff --git a/src/Factory/Api/Mastodon/StatusSource.php b/src/Factory/Api/Mastodon/StatusSource.php index b0d2511156..67a0526bee 100644 --- a/src/Factory/Api/Mastodon/StatusSource.php +++ b/src/Factory/Api/Mastodon/StatusSource.php @@ -20,7 +20,8 @@ class StatusSource extends BaseFactory * * @return \Friendica\Object\Api\Mastodon\StatusSource * @throws HTTPException\InternalServerErrorException - * @throws \ImagickException*@throws \Exception + * @throws \ImagickException + * @throws \Exception */ public function createFromUriId(int $uriId, int $uid): \Friendica\Object\Api\Mastodon\StatusSource { diff --git a/src/Factory/Api/Mastodon/Subscription.php b/src/Factory/Api/Mastodon/Subscription.php index 61d71850e3..b0aa56f964 100644 --- a/src/Factory/Api/Mastodon/Subscription.php +++ b/src/Factory/Api/Mastodon/Subscription.php @@ -10,18 +10,17 @@ namespace Friendica\Factory\Api\Mastodon; use Friendica\BaseFactory; use Friendica\Database\DBA; use Friendica\Model\Subscription as ModelSubscription; +use Friendica\Object\Api\Mastodon\Subscription as SubscriptionObject; class Subscription extends BaseFactory { /** * @param int $applicationid Application Id * @param int $uid Item user - * - * @return \Friendica\Object\Api\Mastodon\Status */ - public function createForApplicationIdAndUserId(int $applicationid, int $uid): \Friendica\Object\Api\Mastodon\Subscription + public function createForApplicationIdAndUserId(int $applicationid, int $uid): SubscriptionObject { $subscription = DBA::selectFirst('subscription', [], ['application-id' => $applicationid, 'uid' => $uid]); - return new \Friendica\Object\Api\Mastodon\Subscription($subscription, ModelSubscription::getPublicVapidKey()); + return new SubscriptionObject($subscription, ModelSubscription::getPublicVapidKey()); } } diff --git a/src/Factory/Api/Twitter/Status.php b/src/Factory/Api/Twitter/Status.php index 084156b382..b31a89fc44 100644 --- a/src/Factory/Api/Twitter/Status.php +++ b/src/Factory/Api/Twitter/Status.php @@ -17,7 +17,8 @@ use Friendica\Factory\Api\Twitter\User as TwitterUser; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\Verb; -use Friendica\Network\HTTPException; +use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\NotFoundException; use Friendica\Protocol\Activity; use ImagickException; use Psr\Log\LoggerInterface; @@ -58,13 +59,13 @@ class Status extends BaseFactory } /** - * @param int $uriId Uri-ID of the item + * @param int $id Uri-ID of the item * @param int $uid Item user * @param bool $include_entities Whether to include entities * * @return \Friendica\Object\Api\Twitter\Status - * @throws HTTPException\InternalServerErrorException - * @throws ImagickException|HTTPException\NotFoundException + * @throws InternalServerErrorException + * @throws ImagickException|NotFoundException */ public function createFromItemId(int $id, int $uid, bool $include_entities = false): \Friendica\Object\Api\Twitter\Status { @@ -73,7 +74,7 @@ class Status extends BaseFactory 'thr-parent-id', 'parent-author-id', 'parent-author-nick', 'uri', 'plink', 'private', 'vid', 'coord', 'quote-uri-id']; $item = Post::selectFirst($fields, ['id' => $id], ['order' => ['uid' => true]]); if (!$item) { - throw new HTTPException\NotFoundException('Item with ID ' . $id . ' not found.'); + throw new NotFoundException('Item with ID ' . $id . ' not found.'); } return $this->createFromArray($item, $uid, $include_entities); } @@ -84,8 +85,8 @@ class Status extends BaseFactory * @param bool $include_entities Whether to include entities * * @return \Friendica\Object\Api\Twitter\Status - * @throws HTTPException\InternalServerErrorException - * @throws ImagickException|HTTPException\NotFoundException + * @throws InternalServerErrorException + * @throws ImagickException|NotFoundException */ public function createFromUriId(int $uriId, int $uid = 0, bool $include_entities = false): \Friendica\Object\Api\Twitter\Status { @@ -94,7 +95,7 @@ class Status extends BaseFactory 'thr-parent-id', 'parent-author-id', 'parent-author-nick', 'uri', 'plink', 'private', 'vid', 'coord']; $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]); if (!$item) { - throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.')); + throw new NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.')); } return $this->createFromArray($item, $uid, $include_entities); } @@ -105,8 +106,8 @@ class Status extends BaseFactory * @param bool $include_entities Whether to include entities * * @return \Friendica\Object\Api\Twitter\Status - * @throws HTTPException\InternalServerErrorException - * @throws ImagickException|HTTPException\NotFoundException + * @throws InternalServerErrorException + * @throws ImagickException|NotFoundException */ private function createFromArray(array $item, int $uid, bool $include_entities): \Friendica\Object\Api\Twitter\Status { @@ -161,8 +162,8 @@ class Status extends BaseFactory if ($include_entities) { $hashtags = $this->hashtag->createFromUriId($item['uri-id'], $text); $medias = $this->media->createFromUriId($item['uri-id'], $text); - $urls = $this->url->createFromUriId($item['uri-id'], $text); - $mentions = $this->mention->createFromUriId($item['uri-id'], $text); + $urls = $this->url->createFromUriId($item['uri-id']); + $mentions = $this->mention->createFromUriId($item['uri-id']); } else { $attachments = $this->attachment->createFromUriId($item['uri-id'], $text); } @@ -176,8 +177,8 @@ class Status extends BaseFactory if ($include_entities) { $hashtags = array_merge($hashtags, $this->hashtag->createFromUriId($shared_uri_id, $text)); $medias = array_merge($medias, $this->media->createFromUriId($shared_uri_id, $text)); - $urls = array_merge($urls, $this->url->createFromUriId($shared_uri_id, $text)); - $mentions = array_merge($mentions, $this->mention->createFromUriId($shared_uri_id, $text)); + $urls = array_merge($urls, $this->url->createFromUriId($shared_uri_id)); + $mentions = array_merge($mentions, $this->mention->createFromUriId($shared_uri_id)); } else { $attachments = array_merge($attachments, $this->attachment->createFromUriId($shared_uri_id, $text)); } diff --git a/src/Navigation/Notifications/Entity/Notification.php b/src/Navigation/Notifications/Entity/Notification.php index 21cf897893..a75b55eea4 100644 --- a/src/Navigation/Notifications/Entity/Notification.php +++ b/src/Navigation/Notifications/Entity/Notification.php @@ -11,16 +11,16 @@ use DateTime; use Friendica\BaseEntity; /** - * @property-read $id - * @property-read $uid - * @property-read $verb - * @property-read $type - * @property-read $actorId - * @property-read $targetUriId - * @property-read $parentUriId - * @property-read $created - * @property-read $seen - * @property-read $dismissed + * @property-read int $id + * @property-read int $uid + * @property-read string $verb + * @property-read int $type + * @property-read int $actorId + * @property-read int $targetUriId + * @property-read int $parentUriId + * @property-read DateTime $created + * @property-read bool $seen + * @property-read bool $dismissed */ class Notification extends BaseEntity { @@ -31,7 +31,7 @@ class Notification extends BaseEntity /** @var string */ protected $verb; /** - * @var int One of the \Friendica\Model\Post\UserNotification::TYPE_* constant values + * @var int $type One of the \Friendica\Model\Post\UserNotification::TYPE_* constant values * @see \Friendica\Model\Post\UserNotification */ protected $type; diff --git a/src/Object/Api/Mastodon/Status/Counts.php b/src/Object/Api/Mastodon/Status/Counts.php index 959c973c5f..f273b342e7 100644 --- a/src/Object/Api/Mastodon/Status/Counts.php +++ b/src/Object/Api/Mastodon/Status/Counts.php @@ -11,6 +11,8 @@ namespace Friendica\Object\Api\Mastodon\Status; * Class Counts * * @see https://docs.joinmastodon.org/entities/status + * + * @property-read int $dislikes */ class Counts {