Fix errors in Factory namespace

This commit is contained in:
Art4 2024-12-03 21:44:35 +00:00
parent 1fe730f514
commit 06e3051ad1
10 changed files with 71 additions and 56 deletions

View file

@ -7,7 +7,7 @@
namespace Friendica; 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. * 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 * 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 * 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 abstract class BaseEntity extends BaseDataTransferObject
{ {
/** /**
* @param string $name * @param string $name
* @return mixed * @return mixed
* @throws HTTPException\InternalServerErrorException * @throws InternalServerErrorException
*/ */
public function __get(string $name) public function __get(string $name)
{ {
if (!property_exists($this, $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; return $this->$name;
@ -43,12 +54,12 @@ abstract class BaseEntity extends BaseDataTransferObject
/** /**
* @param mixed $name * @param mixed $name
* @return bool * @return bool
* @throws HTTPException\InternalServerErrorException * @throws InternalServerErrorException
*/ */
public function __isset($name): bool public function __isset($name): bool
{ {
if (!property_exists($this, $name)) { 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); return !empty($this->$name);

View file

@ -525,7 +525,7 @@ abstract class DI
// //
/** /**
* @return Contact\FriendSuggest\Repository\FriendSuggest; * @return Contact\FriendSuggest\Repository\FriendSuggest
*/ */
public static function fsuggest() 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() public static function fsuggestFactory()
{ {

View file

@ -8,10 +8,8 @@
namespace Friendica\Factory\Api\Mastodon; namespace Friendica\Factory\Api\Mastodon;
use Friendica\BaseFactory; use Friendica\BaseFactory;
use Friendica\Content\Text\BBCode;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Util\Strings;
class Card extends BaseFactory class Card extends BaseFactory
{ {
@ -21,7 +19,8 @@ class Card extends BaseFactory
* *
* @return \Friendica\Object\Api\Mastodon\Card * @return \Friendica\Object\Api\Mastodon\Card
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
* @throws \ImagickException*@throws \Exception * @throws \ImagickException
* @throws \Exception
*/ */
public function createFromUriId(int $uriId, array $history = []): \Friendica\Object\Api\Mastodon\Card public function createFromUriId(int $uriId, array $history = []): \Friendica\Object\Api\Mastodon\Card
{ {

View file

@ -9,7 +9,7 @@ namespace Friendica\Factory\Api\Mastodon;
use Friendica\BaseFactory; use Friendica\BaseFactory;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Navigation\Notifications; use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity;
use Friendica\Navigation\Notifications\Exception\UnexpectedNotificationTypeException; use Friendica\Navigation\Notifications\Exception\UnexpectedNotificationTypeException;
use Friendica\Object\Api\Mastodon\Notification as MstdnNotification; use Friendica\Object\Api\Mastodon\Notification as MstdnNotification;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -32,16 +32,17 @@ class Notification extends BaseFactory
} }
/** /**
* @param Notifications\Entity\Notification $Notification * @param NotificationEntity $Notification
* @param bool $display_quote Display quoted posts * @param bool $display_quotes Display quoted posts
* *
* @return MstdnNotification * @return MstdnNotification
* @throws UnexpectedNotificationTypeException * @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); $type = self::getType($Notification);
if (empty($type)) {
if ($type === '') {
throw new UnexpectedNotificationTypeException(); throw new UnexpectedNotificationTypeException();
} }

View file

@ -20,7 +20,8 @@ use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Verb; 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\FriendicaDeliveryData;
use Friendica\Object\Api\Mastodon\Status\FriendicaExtension; use Friendica\Object\Api\Mastodon\Status\FriendicaExtension;
use Friendica\Object\Api\Mastodon\Status\FriendicaVisibility; 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 * @param bool $in_reply_status Add an "in_reply_status" element
* *
* @return \Friendica\Object\Api\Mastodon\Status * @return \Friendica\Object\Api\Mastodon\Status
* @throws HTTPException\InternalServerErrorException * @throws InternalServerErrorException
* @throws ImagickException|HTTPException\NotFoundException * @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 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) { if ($mail) {
return $this->createFromMailId($mail['id']); 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']; $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; $activity = $item;
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]); $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
if (!$item) { 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) { foreach ($activity_fields as $field) {
$item[$field] = $activity[$field]; $item[$field] = $activity[$field];
@ -202,7 +203,7 @@ class Status extends BaseFactory
$sensitive = (bool)$item['sensitive']; $sensitive = (bool)$item['sensitive'];
$network = ContactSelector::networkToName($item['network']); $network = ContactSelector::networkToName($item['network']);
$sitename = ''; $sitename = '';
$platform = ''; $platform = '';
$version = ''; $version = '';
@ -211,7 +212,7 @@ class Status extends BaseFactory
if (!empty($gserver)) { if (!empty($gserver)) {
$platform = ucfirst($gserver['platform']); $platform = ucfirst($gserver['platform']);
$version = $gserver['version']; $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 * @return \Friendica\Object\Api\Mastodon\Status
* @throws HTTPException\InternalServerErrorException * @throws InternalServerErrorException
* @throws ImagickException|HTTPException\NotFoundException * @throws ImagickException|NotFoundException
*/ */
public function createFromMailId(int $id): \Friendica\Object\Api\Mastodon\Status public function createFromMailId(int $id): \Friendica\Object\Api\Mastodon\Status
{ {
$item = ActivityPub\Transmitter::getItemArrayFromMail($id, true); $item = ActivityPub\Transmitter::getItemArrayFromMail($id, true);
if (empty($item)) { 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']); $account = $this->mstdnAccountFactory->createFromContactId($item['author-id']);

View file

@ -20,7 +20,8 @@ class StatusSource extends BaseFactory
* *
* @return \Friendica\Object\Api\Mastodon\StatusSource * @return \Friendica\Object\Api\Mastodon\StatusSource
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
* @throws \ImagickException*@throws \Exception * @throws \ImagickException
* @throws \Exception
*/ */
public function createFromUriId(int $uriId, int $uid): \Friendica\Object\Api\Mastodon\StatusSource public function createFromUriId(int $uriId, int $uid): \Friendica\Object\Api\Mastodon\StatusSource
{ {

View file

@ -10,18 +10,17 @@ namespace Friendica\Factory\Api\Mastodon;
use Friendica\BaseFactory; use Friendica\BaseFactory;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Subscription as ModelSubscription; use Friendica\Model\Subscription as ModelSubscription;
use Friendica\Object\Api\Mastodon\Subscription as SubscriptionObject;
class Subscription extends BaseFactory class Subscription extends BaseFactory
{ {
/** /**
* @param int $applicationid Application Id * @param int $applicationid Application Id
* @param int $uid Item user * @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]); $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());
} }
} }

View file

@ -17,7 +17,8 @@ use Friendica\Factory\Api\Twitter\User as TwitterUser;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Verb; use Friendica\Model\Verb;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use ImagickException; use ImagickException;
use Psr\Log\LoggerInterface; 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 int $uid Item user
* @param bool $include_entities Whether to include entities * @param bool $include_entities Whether to include entities
* *
* @return \Friendica\Object\Api\Twitter\Status * @return \Friendica\Object\Api\Twitter\Status
* @throws HTTPException\InternalServerErrorException * @throws InternalServerErrorException
* @throws ImagickException|HTTPException\NotFoundException * @throws ImagickException|NotFoundException
*/ */
public function createFromItemId(int $id, int $uid, bool $include_entities = false): \Friendica\Object\Api\Twitter\Status 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']; '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]]); $item = Post::selectFirst($fields, ['id' => $id], ['order' => ['uid' => true]]);
if (!$item) { 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); return $this->createFromArray($item, $uid, $include_entities);
} }
@ -84,8 +85,8 @@ class Status extends BaseFactory
* @param bool $include_entities Whether to include entities * @param bool $include_entities Whether to include entities
* *
* @return \Friendica\Object\Api\Twitter\Status * @return \Friendica\Object\Api\Twitter\Status
* @throws HTTPException\InternalServerErrorException * @throws InternalServerErrorException
* @throws ImagickException|HTTPException\NotFoundException * @throws ImagickException|NotFoundException
*/ */
public function createFromUriId(int $uriId, int $uid = 0, bool $include_entities = false): \Friendica\Object\Api\Twitter\Status 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']; '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]]); $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
if (!$item) { 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); return $this->createFromArray($item, $uid, $include_entities);
} }
@ -105,8 +106,8 @@ class Status extends BaseFactory
* @param bool $include_entities Whether to include entities * @param bool $include_entities Whether to include entities
* *
* @return \Friendica\Object\Api\Twitter\Status * @return \Friendica\Object\Api\Twitter\Status
* @throws HTTPException\InternalServerErrorException * @throws InternalServerErrorException
* @throws ImagickException|HTTPException\NotFoundException * @throws ImagickException|NotFoundException
*/ */
private function createFromArray(array $item, int $uid, bool $include_entities): \Friendica\Object\Api\Twitter\Status 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) { if ($include_entities) {
$hashtags = $this->hashtag->createFromUriId($item['uri-id'], $text); $hashtags = $this->hashtag->createFromUriId($item['uri-id'], $text);
$medias = $this->media->createFromUriId($item['uri-id'], $text); $medias = $this->media->createFromUriId($item['uri-id'], $text);
$urls = $this->url->createFromUriId($item['uri-id'], $text); $urls = $this->url->createFromUriId($item['uri-id']);
$mentions = $this->mention->createFromUriId($item['uri-id'], $text); $mentions = $this->mention->createFromUriId($item['uri-id']);
} else { } else {
$attachments = $this->attachment->createFromUriId($item['uri-id'], $text); $attachments = $this->attachment->createFromUriId($item['uri-id'], $text);
} }
@ -176,8 +177,8 @@ class Status extends BaseFactory
if ($include_entities) { if ($include_entities) {
$hashtags = array_merge($hashtags, $this->hashtag->createFromUriId($shared_uri_id, $text)); $hashtags = array_merge($hashtags, $this->hashtag->createFromUriId($shared_uri_id, $text));
$medias = array_merge($medias, $this->media->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)); $urls = array_merge($urls, $this->url->createFromUriId($shared_uri_id));
$mentions = array_merge($mentions, $this->mention->createFromUriId($shared_uri_id, $text)); $mentions = array_merge($mentions, $this->mention->createFromUriId($shared_uri_id));
} else { } else {
$attachments = array_merge($attachments, $this->attachment->createFromUriId($shared_uri_id, $text)); $attachments = array_merge($attachments, $this->attachment->createFromUriId($shared_uri_id, $text));
} }

View file

@ -11,16 +11,16 @@ use DateTime;
use Friendica\BaseEntity; use Friendica\BaseEntity;
/** /**
* @property-read $id * @property-read int $id
* @property-read $uid * @property-read int $uid
* @property-read $verb * @property-read string $verb
* @property-read $type * @property-read int $type
* @property-read $actorId * @property-read int $actorId
* @property-read $targetUriId * @property-read int $targetUriId
* @property-read $parentUriId * @property-read int $parentUriId
* @property-read $created * @property-read DateTime $created
* @property-read $seen * @property-read bool $seen
* @property-read $dismissed * @property-read bool $dismissed
*/ */
class Notification extends BaseEntity class Notification extends BaseEntity
{ {
@ -31,7 +31,7 @@ class Notification extends BaseEntity
/** @var string */ /** @var string */
protected $verb; 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 * @see \Friendica\Model\Post\UserNotification
*/ */
protected $type; protected $type;

View file

@ -11,6 +11,8 @@ namespace Friendica\Object\Api\Mastodon\Status;
* Class Counts * Class Counts
* *
* @see https://docs.joinmastodon.org/entities/status * @see https://docs.joinmastodon.org/entities/status
*
* @property-read int $dislikes
*/ */
class Counts class Counts
{ {