From cea8cf1f6c5aaea5b99eae799719930f28ab409d Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 25 Feb 2025 13:51:13 +0000 Subject: [PATCH] Fix 27 PHPStan errors --- .../Notifications/Entity/Notify.php | 3 ++- src/Object/Api/Mastodon/Status.php | 18 ++++++------- src/Object/Api/Twitter/DirectMessage.php | 4 +-- src/Object/Api/Twitter/Media.php | 2 +- src/Object/Api/Twitter/Mention.php | 3 +-- src/Object/Api/Twitter/Status.php | 10 ++++---- src/Object/Log/ParsedLogLine.php | 2 +- src/Object/Post.php | 4 +-- src/Object/Thread.php | 3 +-- .../ProfileField/Collection/ProfileFields.php | 25 ++++++++----------- 10 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/Navigation/Notifications/Entity/Notify.php b/src/Navigation/Notifications/Entity/Notify.php index 3ff478633e..297ecbdd98 100644 --- a/src/Navigation/Notifications/Entity/Notify.php +++ b/src/Navigation/Notifications/Entity/Notify.php @@ -33,7 +33,8 @@ use Psr\Http\Message\UriInterface; * @property-read int|null $parentUriId * @property-read int|null $id * - * @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\Entity\Notification instead + * @deprecated 2022.05 Use \Friendica\Navigation\Notifications\Entity\Notification instead + * @see \Friendica\Navigation\Notifications\Entity\Notification */ class Notify extends BaseEntity { diff --git a/src/Object/Api/Mastodon/Status.php b/src/Object/Api/Mastodon/Status.php index 0e487a989c..474db28dc0 100644 --- a/src/Object/Api/Mastodon/Status.php +++ b/src/Object/Api/Mastodon/Status.php @@ -30,7 +30,7 @@ class Status extends BaseDataTransferObject protected $edited_at; /** @var string|null */ protected $in_reply_to_id = null; - /** @var Status|null - Fedilab extension, see issue https://github.com/friendica/friendica/issues/12672 */ + /** @var Status[]|null - Fedilab extension, see issue https://github.com/friendica/friendica/issues/12672 */ protected $in_reply_to_status = null; /** @var string|null */ protected $in_reply_to_account_id = null; @@ -64,25 +64,25 @@ class Status extends BaseDataTransferObject protected $pinned = false; /** @var string */ protected $content; - /** @var Status|null */ + /** @var Status[]|null */ protected $reblog = null; - /** @var Status|null - Akkoma extension, see issue https://github.com/friendica/friendica/issues/12603 */ + /** @var Status[]|null - Akkoma extension, see issue https://github.com/friendica/friendica/issues/12603 */ protected $quote = null; /** @var Application */ protected $application = null; - /** @var Account */ + /** @var array */ protected $account; - /** @var Attachment */ + /** @var Attachment[] */ protected $media_attachments = []; - /** @var Mention */ + /** @var Mention[] */ protected $mentions = []; - /** @var Tag */ + /** @var Tag[] */ protected $tags = []; /** @var Emoji[] */ protected $emojis = []; - /** @var Card|null */ + /** @var array|null */ protected $card = null; - /** @var Poll|null */ + /** @var array|null */ protected $poll = null; /** @var FriendicaExtension */ protected $friendica; diff --git a/src/Object/Api/Twitter/DirectMessage.php b/src/Object/Api/Twitter/DirectMessage.php index 10bea34290..199d9462ed 100644 --- a/src/Object/Api/Twitter/DirectMessage.php +++ b/src/Object/Api/Twitter/DirectMessage.php @@ -29,9 +29,9 @@ class DirectMessage extends BaseDataTransferObject protected $sender_screen_name = null; /** @var string */ protected $recipient_screen_name = null; - /** @var User */ + /** @var array */ protected $sender; - /** @var User */ + /** @var array */ protected $recipient; /** @var string|null */ protected $title; diff --git a/src/Object/Api/Twitter/Media.php b/src/Object/Api/Twitter/Media.php index 19f98f1a29..589aebcfc1 100644 --- a/src/Object/Api/Twitter/Media.php +++ b/src/Object/Api/Twitter/Media.php @@ -31,7 +31,7 @@ class Media extends BaseDataTransferObject protected $media_url; /** @var string */ protected $media_url_https; - /** @var string */ + /** @var array> */ protected $sizes; /** @var string */ protected $type; diff --git a/src/Object/Api/Twitter/Mention.php b/src/Object/Api/Twitter/Mention.php index e5d257e9d3..d2a4d5065f 100644 --- a/src/Object/Api/Twitter/Mention.php +++ b/src/Object/Api/Twitter/Mention.php @@ -7,7 +7,6 @@ namespace Friendica\Object\Api\Twitter; -use Friendica\App\BaseURL; use Friendica\BaseDataTransferObject; /** @@ -37,7 +36,7 @@ class Mention extends BaseDataTransferObject */ public function __construct(array $tag, array $contact, array $indices) { - $this->id = (string)($contact['id'] ?? 0); + $this->id = (int)($contact['id'] ?? 0); $this->id_str = (string)($contact['id'] ?? 0); $this->indices = $indices; $this->name = $tag['name']; diff --git a/src/Object/Api/Twitter/Status.php b/src/Object/Api/Twitter/Status.php index 793f32fb01..1c8a4ef7ae 100644 --- a/src/Object/Api/Twitter/Status.php +++ b/src/Object/Api/Twitter/Status.php @@ -45,11 +45,11 @@ class Status extends BaseDataTransferObject protected $geo; /** @var bool */ protected $favorited = false; - /** @var User */ + /** @var array */ protected $user; - /** @var User */ + /** @var array */ protected $friendica_author; - /** @var User */ + /** @var array */ protected $friendica_owner; /** @var bool */ protected $friendica_private; @@ -67,9 +67,9 @@ class Status extends BaseDataTransferObject protected $friendica_html; /** @var int */ protected $friendica_comments; - /** @var Status|null */ + /** @var array|null */ protected $retweeted_status = null; - /** @var Status|null */ + /** @var array|null */ protected $quoted_status = null; /** @var array */ protected $attachments; diff --git a/src/Object/Log/ParsedLogLine.php b/src/Object/Log/ParsedLogLine.php index 1d9802bb32..8e552008a4 100644 --- a/src/Object/Log/ParsedLogLine.php +++ b/src/Object/Log/ParsedLogLine.php @@ -29,7 +29,7 @@ class ParsedLogLine /** @var string */ public $message = null; - /** @var string */ + /** @var string|null */ public $data = null; /** @var string */ diff --git a/src/Object/Post.php b/src/Object/Post.php index b5ad33f56e..abf617e214 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -49,7 +49,7 @@ class Post private $parent = null; /** - * @var Thread + * @var Thread|null */ private $thread = null; private $redirect_url = null; @@ -816,7 +816,7 @@ class Post * Get a child by its ID * * @param integer $id The child id - * @return Thread|null Thread or NULL if not found + * @return Post|null Post or NULL if not found */ public function getChild(int $id) { diff --git a/src/Object/Thread.php b/src/Object/Thread.php index 453e4c3421..070d8c1281 100644 --- a/src/Object/Thread.php +++ b/src/Object/Thread.php @@ -77,8 +77,7 @@ class Thread break; default: DI::logger()->info('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').'); - return false; - break; + return; } $this->mode = $mode; } diff --git a/src/Profile/ProfileField/Collection/ProfileFields.php b/src/Profile/ProfileField/Collection/ProfileFields.php index fa39a6f355..dcf5498df3 100644 --- a/src/Profile/ProfileField/Collection/ProfileFields.php +++ b/src/Profile/ProfileField/Collection/ProfileFields.php @@ -8,31 +8,26 @@ namespace Friendica\Profile\ProfileField\Collection; use Friendica\BaseCollection; -use Friendica\Profile\ProfileField\Entity; +use Friendica\Profile\ProfileField\Entity\ProfileField as ProfileFieldEntity; class ProfileFields extends BaseCollection { - public function current(): Entity\ProfileField + public function current(): ProfileFieldEntity { return parent::current(); } - /** - * @param callable $callback - * @return ProfileFields (as an extended form of BaseCollection) - */ - public function map(callable $callback): BaseCollection + public function map(callable $callback): ProfileFields { - return parent::map($callback); + $class = get_class($this); + + return new $class(array_map($callback, $this->getArrayCopy()), $this->getTotalCount()); } - /** - * @param callable|null $callback - * @param int $flag - * @return ProfileFields as an extended version of BaseCollection - */ - public function filter(callable $callback = null, int $flag = 0): BaseCollection + public function filter(?callable $callback = null, int $flag = 0): ProfileFields { - return parent::filter($callback, $flag); + $class = get_class($this); + + return new $class(array_filter($this->getArrayCopy(), $callback, $flag)); } }