From ec28f23025c2b324a366ffaecb4b3705ffb4c257 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 26 Dec 2021 09:48:16 +0000 Subject: [PATCH] [TOOLS] Run CS-fixer on all files --- .../Attachment/Controller/Attachment.php | 2 +- .../Attachment/Entity/ActorToAttachment.php | 17 +--- components/Attachment/Entity/Attachment.php | 46 +++------- .../Attachment/Entity/AttachmentToLink.php | 17 +--- .../Attachment/Entity/AttachmentToNote.php | 18 +--- components/Avatar/Entity/Avatar.php | 2 +- .../FreeNetwork/Controller/HostMeta.php | 6 +- .../FreeNetwork/Controller/OwnerXrd.php | 3 +- .../FreeNetwork/Controller/Webfinger.php | 4 +- .../Entity/FreeNetworkActorProtocol.php | 22 ++--- .../WebfingerReconstructionException.php | 4 +- components/FreeNetwork/Util/LinkHeader.php | 12 +-- .../Util/LrddMethod/LrddMethodHostMeta.php | 12 +-- .../Util/LrddMethod/LrddMethodLinkHtml.php | 19 ++-- .../Util/LrddMethod/LrddMethodWebfinger.php | 14 +-- .../FreeNetwork/Util/WebfingerResource.php | 6 +- .../WebfingerResourceActor.php | 18 ++-- .../WebfingerResourceNote.php | 36 +++++--- components/FreeNetwork/Util/XrdController.php | 4 +- components/Language/Controller/Language.php | 4 +- components/Language/Entity/Language.php | 35 ++++---- components/Link/Entity/NoteToLink.php | 17 +--- .../Notification/Entity/Notification.php | 19 ++-- .../Entity/UserNotificationPrefs.php | 6 +- components/Posting/Posting.php | 2 +- components/Tag/Tag.php | 2 +- .../Entity/ActivitypubActivity.php | 13 +-- .../ActivityPub/Entity/ActivitypubActor.php | 33 ++++--- .../ActivityPub/Entity/ActivitypubObject.php | 15 ++-- plugins/ActivityPub/Entity/ActivitypubRsa.php | 43 ++++----- plugins/ActivityPub/Util/DiscoveryHints.php | 9 +- plugins/ActivityPub/Util/Explorer.php | 37 ++++---- plugins/ActivityPub/Util/HTTPSignature.php | 88 ++++++++---------- plugins/ActivityPub/Util/Model.php | 36 ++++---- plugins/ActivityPub/Util/Model/Activity.php | 65 +++++++------- plugins/ActivityPub/Util/Model/Actor.php | 78 ++++++++-------- plugins/ActivityPub/Util/Model/Note.php | 27 +++--- plugins/ActivityPub/Util/ModelResponse.php | 6 +- plugins/ActivityPub/Util/ModelValidator.php | 3 +- .../Util/Response/ActivityResponse.php | 6 +- .../Util/Response/ActorResponse.php | 6 +- .../Util/Response/NoteResponse.php | 5 +- plugins/ActivityPub/Util/TypeResponse.php | 9 +- .../Validator/contentLangModelValidator.php | 7 +- ...anuallyApprovesFollowersModelValidator.php | 7 +- .../Controller/Controller.php | 43 ++++----- .../Entity/Collection.php | 11 +-- .../Entity/CollectionEntry.php | 7 +- plugins/AudioEncoder/AudioEncoder.php | 22 ++--- plugins/Cover/Entity/Cover.php | 2 +- plugins/Embed/Entity/AttachmentEmbed.php | 4 +- plugins/ImageEncoder/ImageEncoder.php | 3 +- plugins/Oomox/Controller/Oomox.php | 89 +++++++++---------- plugins/Oomox/Entity/Oomox.php | 16 ++-- plugins/RepeatNote/RepeatNote.php | 12 +-- .../Controller/AddBlocked.php | 2 +- plugins/TreeNotes/TreeNotes.php | 2 +- src/Core/Entity.php | 2 +- src/Util/Exception/BugFoundException.php | 2 +- .../Exception/FileNotAllowedException.php | 4 +- src/Util/Exception/NoSuchActorException.php | 2 + src/Util/Form/FormFields.php | 2 +- src/Util/Formatting.php | 2 +- src/Util/Notification/Notification.php | 2 +- tests/Entity/AttachmentTest.php | 2 +- tests/Entity/AttachmentThumbnailTest.php | 2 +- 66 files changed, 494 insertions(+), 579 deletions(-) diff --git a/components/Attachment/Controller/Attachment.php b/components/Attachment/Controller/Attachment.php index 153b41dfa9..f5ea6e3908 100644 --- a/components/Attachment/Controller/Attachment.php +++ b/components/Attachment/Controller/Attachment.php @@ -30,12 +30,12 @@ use App\Core\GSFile; use function App\Core\I18n\_m; use App\Core\Log; use App\Core\Router\Router; -use Component\Attachment\Entity\AttachmentThumbnail; use App\Util\Common; use App\Util\Exception\ClientException; use App\Util\Exception\NoSuchFileException; use App\Util\Exception\NotFoundException; use App\Util\Exception\ServerException; +use Component\Attachment\Entity\AttachmentThumbnail; use Symfony\Component\HttpFoundation\HeaderUtils; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; diff --git a/components/Attachment/Entity/ActorToAttachment.php b/components/Attachment/Entity/ActorToAttachment.php index 2a2c4630fd..3df8af8179 100644 --- a/components/Attachment/Entity/ActorToAttachment.php +++ b/components/Attachment/Entity/ActorToAttachment.php @@ -1,5 +1,7 @@ id; } - /** - * @return int - */ public function getLives(): int { return $this->lives; } - /** - * @param int $lives - */ public function setLives(int $lives): void { $this->lives = $lives; @@ -176,39 +172,31 @@ class Attachment extends Entity public function getMimetypeMajor(): ?string { $mime = $this->getMimetype(); - return is_null($mime) ? $mime : GSFile::mimetypeMajor($mime); + return \is_null($mime) ? $mime : GSFile::mimetypeMajor($mime); } public function getMimetypeMinor(): ?string { $mime = $this->getMimetype(); - return is_null($mime) ? $mime : GSFile::mimetypeMinor($mime); + return \is_null($mime) ? $mime : GSFile::mimetypeMinor($mime); } - /** - * @return int - */ public function livesIncrementAndGet(): int { ++$this->lives; return $this->lives; } - /** - * @return int - */ public function livesDecrementAndGet(): int { --$this->lives; return $this->lives; } - const FILEHASH_ALGO = 'sha256'; + public const FILEHASH_ALGO = 'sha256'; /** * Delete a file if safe, removes dependencies, cleanups and flushes - * - * @return bool */ public function kill(): bool { @@ -223,7 +211,7 @@ class Attachment extends Entity */ public function deleteStorage(): bool { - if (!is_null($filepath = $this->getPath())) { + if (!\is_null($filepath = $this->getPath())) { if (file_exists($filepath)) { if (@unlink($filepath) === false) { // @codeCoverageIgnoreStart @@ -248,6 +236,7 @@ class Attachment extends Entity /** * Attachment delete always removes dependencies, cleanups and flushes + * * @see kill() It's more likely that you want to use that rather than call delete directly */ protected function delete(): bool @@ -261,7 +250,7 @@ class Attachment extends Entity // Collect files starting with the one associated with this attachment $files = []; - if (!is_null($filepath = $this->getPath())) { + if (!\is_null($filepath = $this->getPath())) { $files[] = $filepath; } @@ -306,25 +295,21 @@ class Attachment extends Entity /** * TODO: Maybe this isn't the best way of handling titles * - * @param null|Note $note - * * @throws DuplicateFoundException * @throws NotFoundException * @throws ServerException - * - * @return string */ public function getBestTitle(?Note $note = null): string { // If we have a note, then the best title is the title itself - if (!is_null(($note))) { + if (!\is_null(($note))) { $title = Cache::get('attachment-title-' . $this->getId() . '-' . $note->getId(), function () use ($note) { try { $attachment_to_note = DB::findOneBy('attachment_to_note', [ 'attachment_id' => $this->getId(), 'note_id' => $note->getId(), ]); - if (!is_null($attachment_to_note->getTitle())) { + if (!\is_null($attachment_to_note->getTitle())) { return $attachment_to_note->getTitle(); } } catch (NotFoundException) { @@ -332,14 +317,14 @@ class Attachment extends Entity Event::handle('AttachmentGetBestTitle', [$this, $note, &$title]); return $title; } - return null; + }); if ($title != null) { return $title; } } // Else - if (!is_null($filename = $this->getFilename())) { + if (!\is_null($filename = $this->getFilename())) { // A filename would do just as well return $filename; } else { @@ -359,7 +344,7 @@ class Attachment extends Entity public function getPath() { $filename = $this->getFilename(); - return is_null($filename) ? null : Common::config('attachments', 'dir') . DIRECTORY_SEPARATOR . $filename; + return \is_null($filename) ? null : Common::config('attachments', 'dir') . \DIRECTORY_SEPARATOR . $filename; } public function getUrl(int $type = Router::ABSOLUTE_URL): string @@ -368,9 +353,6 @@ class Attachment extends Entity } /** - * @param null|string $size - * @param bool $crop - * * @throws ClientException * @throws NotFoundException * @throws ServerException diff --git a/components/Attachment/Entity/AttachmentToLink.php b/components/Attachment/Entity/AttachmentToLink.php index 56b9c5f80c..5af047cd98 100644 --- a/components/Attachment/Entity/AttachmentToLink.php +++ b/components/Attachment/Entity/AttachmentToLink.php @@ -1,5 +1,7 @@ * @author Craig Andrews @@ -8,13 +10,9 @@ namespace Component\FreeNetwork\Controller; -use App\Core\Controller; use App\Core\Event; use Component\FreeNetwork\Util\Discovery; use Component\FreeNetwork\Util\XrdController; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; -use XML_XRD; class HostMeta extends XrdController { diff --git a/components/FreeNetwork/Controller/OwnerXrd.php b/components/FreeNetwork/Controller/OwnerXrd.php index 0e50a29c5a..7666173812 100644 --- a/components/FreeNetwork/Controller/OwnerXrd.php +++ b/components/FreeNetwork/Controller/OwnerXrd.php @@ -1,4 +1,6 @@ xrd->subject = $this->resource; foreach ($this->target->getAliases() as $alias) { - if ($alias != $this->xrd->subject && !in_array($alias, $this->xrd->aliases)) { + if ($alias != $this->xrd->subject && !\in_array($alias, $this->xrd->aliases)) { $this->xrd->aliases[] = $alias; } } diff --git a/components/FreeNetwork/Entity/FreeNetworkActorProtocol.php b/components/FreeNetwork/Entity/FreeNetworkActorProtocol.php index 4980012438..ae5fca598d 100644 --- a/components/FreeNetwork/Entity/FreeNetworkActorProtocol.php +++ b/components/FreeNetwork/Entity/FreeNetworkActorProtocol.php @@ -32,17 +32,11 @@ declare(strict_types = 1); namespace Component\FreeNetwork\Entity; -use App\Core\Cache; use App\Core\DB\DB; use App\Core\Entity; -use function App\Core\I18n\_m; -use App\Core\Log; use App\Entity\Actor; use Component\FreeNetwork\Util\Discovery; use DateTimeInterface; -use Exception; -use Plugin\ActivityPub\Util\DiscoveryHints; -use Plugin\ActivityPub\Util\Explorer; /** * Table Definition for free_network_actor_protocol @@ -119,9 +113,9 @@ class FreeNetworkActorProtocol extends Entity public static function protocolSucceeded(string $protocol, int|Actor $actor_id, string $addr): void { - $actor_id = is_int($actor_id) ? $actor_id : $actor_id->getId(); + $actor_id = \is_int($actor_id) ? $actor_id : $actor_id->getId(); $attributed_protocol = self::getByPK(['actor_id' => $actor_id]); - if (is_null($attributed_protocol)) { + if (\is_null($attributed_protocol)) { $attributed_protocol = self::create([ 'actor_id' => $actor_id, 'protocol' => $protocol, @@ -130,14 +124,14 @@ class FreeNetworkActorProtocol extends Entity } else { $attributed_protocol->setProtocol($protocol); } - DB::wrapInTransaction(fn() => DB::persist($attributed_protocol)); + DB::wrapInTransaction(fn () => DB::persist($attributed_protocol)); } public static function canIActor(string $protocol, int|Actor $actor_id): bool { - $actor_id = is_int($actor_id) ? $actor_id : $actor_id->getId(); + $actor_id = \is_int($actor_id) ? $actor_id : $actor_id->getId(); $attributed_protocol = self::getByPK(['actor_id' => $actor_id])?->getProtocol(); - if (is_null($attributed_protocol)) { + if (\is_null($attributed_protocol)) { // If it is not attributed, you can go ahead. return true; } else { @@ -149,9 +143,9 @@ class FreeNetworkActorProtocol extends Entity public static function canIAddr(string $protocol, string $target): bool { // Normalize $addr, i.e. add 'acct:' if missing - $addr = Discovery::normalize($target); + $addr = Discovery::normalize($target); $attributed_protocol = self::getByPK(['addr' => $addr])?->getProtocol(); - if (is_null($attributed_protocol)) { + if (\is_null($attributed_protocol)) { // If it is not attributed, you can go ahead. return true; } else { @@ -167,7 +161,7 @@ class FreeNetworkActorProtocol extends Entity 'fields' => [ 'actor_id' => ['type' => 'int', 'not null' => true], 'protocol' => ['type' => 'varchar', 'length' => 32, 'description' => 'the protocol plugin that should handle federation of this actor'], - 'addr' => ['type' => 'text', 'not null' => true, 'description' => 'webfinger acct'], + 'addr' => ['type' => 'text', 'not null' => true, 'description' => 'webfinger acct'], 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], diff --git a/components/FreeNetwork/Exception/WebfingerReconstructionException.php b/components/FreeNetwork/Exception/WebfingerReconstructionException.php index c6a8d62ef7..b19c268f18 100644 --- a/components/FreeNetwork/Exception/WebfingerReconstructionException.php +++ b/components/FreeNetwork/Exception/WebfingerReconstructionException.php @@ -1,4 +1,6 @@ type = null; // remove uri-reference from header - $str = substr($str, strlen($uri_reference[0])); + $str = mb_substr($str, \mb_strlen($uri_reference[0])); // parse link-params $params = explode(';', $str); @@ -78,7 +80,7 @@ class LinkHeader if (empty($param)) { continue; } - list($param_name, $param_value) = explode('=', $param, 2); + [$param_name, $param_value] = explode('=', $param, 2); $param_name = trim($param_name); $param_value = preg_replace('(^"|"$)', '', trim($param_value)); @@ -110,18 +112,18 @@ class LinkHeader $headers = $response->getHeader('Link'); if ($headers) { // Can get an array or string, so try to simplify the path - if (!is_array($headers)) { + if (!\is_array($headers)) { $headers = [$headers]; } foreach ($headers as $header) { $lh = new self($header); - if ((is_null($rel) || $lh->rel == $rel) && (is_null($type) || $lh->type == $type)) { + if ((\is_null($rel) || $lh->rel == $rel) && (\is_null($type) || $lh->type == $type)) { return $lh->href; } } } - return null; + } } diff --git a/components/FreeNetwork/Util/LrddMethod/LrddMethodHostMeta.php b/components/FreeNetwork/Util/LrddMethod/LrddMethodHostMeta.php index e50b49fe3f..8c8f780e5c 100644 --- a/components/FreeNetwork/Util/LrddMethod/LrddMethodHostMeta.php +++ b/components/FreeNetwork/Util/LrddMethod/LrddMethodHostMeta.php @@ -1,5 +1,7 @@ elements * in the HTML response. * - * @param mixed $uri - * * @todo fail out of WebFinger URIs faster - * */ public function discover($uri) { @@ -65,7 +64,7 @@ class LrddMethodLinkHtml extends LRDDMethod preg_match('/]*)?>(.*?)<\/head>/is', $html, $head_matches); - if (count($head_matches) != 3) { + if (\count($head_matches) != 3) { return []; } [, , $head_html] = $head_matches; @@ -78,23 +77,23 @@ class LrddMethodLinkHtml extends LRDDMethod $link_type = null; preg_match('/\srel=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $rel_matches); - if (count($rel_matches) > 3) { + if (\count($rel_matches) > 3) { $link_rel = $rel_matches[3]; - } elseif (count($rel_matches) > 1) { + } elseif (\count($rel_matches) > 1) { $link_rel = $rel_matches[1]; } preg_match('/\shref=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $href_matches); - if (count($href_matches) > 3) { + if (\count($href_matches) > 3) { $link_uri = $href_matches[3]; - } elseif (count($href_matches) > 1) { + } elseif (\count($href_matches) > 1) { $link_uri = $href_matches[1]; } preg_match('/\stype=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $type_matches); - if (count($type_matches) > 3) { + if (\count($type_matches) > 3) { $link_type = $type_matches[3]; - } elseif (count($type_matches) > 1) { + } elseif (\count($type_matches) > 1) { $link_type = $type_matches[1]; } diff --git a/components/FreeNetwork/Util/LrddMethod/LrddMethodWebfinger.php b/components/FreeNetwork/Util/LrddMethod/LrddMethodWebfinger.php index 9d03cc2e3f..f764a3db06 100644 --- a/components/FreeNetwork/Util/LrddMethod/LrddMethodWebfinger.php +++ b/components/FreeNetwork/Util/LrddMethod/LrddMethodWebfinger.php @@ -1,4 +1,6 @@ $id) { - if (!strtolower(parse_url($alias, PHP_URL_SCHEME)) === 'https') { + if (!mb_strtolower(parse_url($alias, \PHP_URL_SCHEME)) === 'https') { continue; } $aliases[preg_replace('/^https:/i', 'http:', $alias, 1)] = $id; diff --git a/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php b/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php index dd52623ca6..bece04a291 100644 --- a/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php +++ b/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php @@ -1,5 +1,7 @@ object, &$acct])) { // TODO: getUri may not always give us the correct host on remote users? - $host = parse_url($this->object->getUri(Router::ABSOLUTE_URL), PHP_URL_HOST); + $host = parse_url($this->object->getUri(Router::ABSOLUTE_URL), \PHP_URL_HOST); if (empty($this->object->getNickname()) || empty($host)) { throw new WebFingerReconstructionException(print_r($this->object, true)); } @@ -75,8 +78,11 @@ class WebfingerResourceActor extends WebFingerResource if (Event::handle('StartWebFingerProfileLinks', [$xrd, $this->object])) { // Profile page, can give more metadata from Link header or HTML parsing - $xrd->links[] = new XML_XRD_Element_Link(self::PROFILEPAGE, - $this->object->getUrl(Router::ABSOLUTE_URL), 'text/html'); + $xrd->links[] = new XML_XRD_Element_Link( + self::PROFILEPAGE, + $this->object->getUrl(Router::ABSOLUTE_URL), + 'text/html', + ); // // XFN // $xrd->links[] = new XML_XRD_Element_Link('http://gmpg.org/xfn/11', diff --git a/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceNote.php b/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceNote.php index b3658fc8fd..f928f11507 100644 --- a/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceNote.php +++ b/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceNote.php @@ -1,5 +1,7 @@ object])) { if ($this->object->isLocal()) { - $xrd->links[] = new XML_XRD_Element_Link('alternate', - common_local_url('ApiStatusesShow', + $xrd->links[] = new XML_XRD_Element_Link( + 'alternate', + common_local_url( + 'ApiStatusesShow', ['id' => $this->object->id, - 'format' => 'atom', ]), - 'application/atom+xml'); + 'format' => 'atom', ], + ), + 'application/atom+xml', + ); - $xrd->links[] = new XML_XRD_Element_Link('alternate', - common_local_url('ApiStatusesShow', + $xrd->links[] = new XML_XRD_Element_Link( + 'alternate', + common_local_url( + 'ApiStatusesShow', ['id' => $this->object->id, - 'format' => 'json', ]), - 'application/json'); + 'format' => 'json', ], + ), + 'application/json', + ); } else { try { - $xrd->links[] = new XML_XRD_Element_Link('alternate', + $xrd->links[] = new XML_XRD_Element_Link( + 'alternate', $this->object->getUrl(), - 'text/html'); + 'text/html', + ); } catch (InvalidUrlException $e) { // don't do a fallback in webfinger } diff --git a/components/FreeNetwork/Util/XrdController.php b/components/FreeNetwork/Util/XrdController.php index d6c16117b4..d116bac440 100644 --- a/components/FreeNetwork/Util/XrdController.php +++ b/components/FreeNetwork/Util/XrdController.php @@ -1,5 +1,7 @@ setXRD(); return ['xrd' => $this->xrd, 'default_mimetype' => $this->default_mimetype]; } -} \ No newline at end of file +} diff --git a/components/Language/Controller/Language.php b/components/Language/Controller/Language.php index 85c9a64178..ee35403b45 100644 --- a/components/Language/Controller/Language.php +++ b/components/Language/Controller/Language.php @@ -28,13 +28,13 @@ use App\Core\Controller; use App\Core\DB\DB; use App\Core\Form; use function App\Core\I18n\_m; -use Component\Language\Entity\ActorLanguage; -use Component\Language\Entity\Language as LangEntity; use App\Util\Common; use App\Util\Exception\NoLoggedInUser; use App\Util\Exception\RedirectException; use App\Util\Exception\ServerException; use App\Util\Form\FormFields; +use Component\Language\Entity\ActorLanguage; +use Component\Language\Entity\Language as LangEntity; use Functional as F; use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; diff --git a/components/Language/Entity/Language.php b/components/Language/Entity/Language.php index 762ccc4219..fc9dd44316 100644 --- a/components/Language/Entity/Language.php +++ b/components/Language/Entity/Language.php @@ -1,6 +1,6 @@ F\reindex(DB::dql('select l from language l'), fn(self $l) => (string)$l->getId()), + key: (string) $id, + calculate_map: fn () => F\reindex(DB::dql('select l from language l'), fn (self $l) => (string) $l->getId()), ); } @@ -125,7 +124,7 @@ class Language extends Entity return Cache::getHashMapKey( 'languages', $locale, - calculate_map: fn() => F\reindex(DB::dql('select l from language l'), fn(self $l) => $l->getLocale()), + calculate_map: fn () => F\reindex(DB::dql('select l from language l'), fn (self $l) => $l->getLocale()), ); } @@ -138,10 +137,10 @@ class Language extends Entity { $langs = Cache::getHashMap( 'languages', - fn() => F\reindex(DB::dql('select l from language l'), fn(self $l) => $l->getLocale()), + fn () => F\reindex(DB::dql('select l from language l'), fn (self $l) => $l->getLocale()), ); - return array_merge(...F\map(array_values($langs), fn($l) => $l->toChoiceFormat())); + return array_merge(...F\map(array_values($langs), fn ($l) => $l->toChoiceFormat())); } public function toChoiceFormat(): array @@ -156,18 +155,18 @@ class Language extends Entity public static function getSortedLanguageChoices(?Actor $actor, ?Actor $context_actor, ?bool $use_short_display): array { $language_choices = self::getLanguageChoices(); - if (is_null($actor)) { + if (\is_null($actor)) { return [$language_choices, []]; } $preferred_language_choices = $actor->getPreferredLanguageChoices($context_actor); ksort($language_choices); if ($use_short_display ?? Common::config('posting', 'use_short_language_display')) { - $key = array_key_first($preferred_language_choices); + $key = array_key_first($preferred_language_choices); $language = $preferred_language_choices[$key]; unset($preferred_language_choices[$key], $language_choices[$key]); - $short_display = $language->getShortDisplay(); + $short_display = $language->getShortDisplay(); $preferred_language_choices[$short_display] = ($locale = $language->getLocale()); - $language_choices[$short_display] = $locale; + $language_choices[$short_display] = $locale; } return [$language_choices, $preferred_language_choices]; } @@ -175,14 +174,14 @@ class Language extends Entity public static function schemaDef(): array { return [ - 'name' => 'language', + 'name' => 'language', 'description' => 'all known languages', - 'fields' => [ - 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'], - 'locale' => ['type' => 'varchar', 'length' => 64, 'description' => 'The locale identifier for the language of a note. 2-leter-iso-language-code_4-leter-script-code_2-leter-iso-country-code, but kept longer in case we get a different format'], - 'long_display' => ['type' => 'varchar', 'length' => 64, 'description' => 'The long display string for the language, in english (translated later)'], + 'fields' => [ + 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'], + 'locale' => ['type' => 'varchar', 'length' => 64, 'description' => 'The locale identifier for the language of a note. 2-leter-iso-language-code_4-leter-script-code_2-leter-iso-country-code, but kept longer in case we get a different format'], + 'long_display' => ['type' => 'varchar', 'length' => 64, 'description' => 'The long display string for the language, in english (translated later)'], 'short_display' => ['type' => 'varchar', 'length' => 12, 'description' => 'The short display string for the language (used for the first option)'], - 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], ], 'primary key' => ['id'], 'unique keys' => [ diff --git a/components/Link/Entity/NoteToLink.php b/components/Link/Entity/NoteToLink.php index a8a6e961fe..a72720377f 100644 --- a/components/Link/Entity/NoteToLink.php +++ b/components/Link/Entity/NoteToLink.php @@ -1,5 +1,7 @@ getTargetId()); @@ -122,18 +121,14 @@ class Notification extends Entity */ public static function getNotificationTargetIdsByActivity(int|Activity $activity_id): array { - $notifications = DB::findBy('notification', ['activity_id' => is_int($activity_id) ? $activity_id : $activity_id->getId()]); - $targets = []; + $notifications = DB::findBy('notification', ['activity_id' => \is_int($activity_id) ? $activity_id : $activity_id->getId()]); + $targets = []; foreach ($notifications as $notification) { $targets[] = $notification->getTargetId(); } return $targets; } - /** - * @param int|Activity $activity_id - * @return array - */ public function getNotificationTargetsByActivity(int|Activity $activity_id): array { return DB::findBy('actor', ['id' => $this->getNotificationTargetIdsByActivity($activity_id)]); @@ -154,7 +149,7 @@ class Notification extends Entity 'primary key' => ['activity_id', 'target_id'], 'indexes' => [ 'attention_activity_id_idx' => ['activity_id'], - 'attention_target_id_idx' => ['target_id'], + 'attention_target_id_idx' => ['target_id'], ], ]; } diff --git a/components/Notification/Entity/UserNotificationPrefs.php b/components/Notification/Entity/UserNotificationPrefs.php index bfaf773026..76d8626ee0 100644 --- a/components/Notification/Entity/UserNotificationPrefs.php +++ b/components/Notification/Entity/UserNotificationPrefs.php @@ -1,5 +1,7 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -106,15 +107,15 @@ class ActivitypubActivity extends Entity public static function schemaDef(): array { return [ - 'name' => 'activitypub_activity', + 'name' => 'activitypub_activity', 'fields' => [ - 'activity_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Activity.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'activity_id to give attention'], + 'activity_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Activity.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'activity_id to give attention'], 'activity_uri' => ['type' => 'text', 'not null' => true, 'description' => 'Activity\'s URI'], - 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], - 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], + 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], 'primary key' => ['activity_uri'], - 'indexes' => [ + 'indexes' => [ 'activity_activity_uri_idx' => ['activity_uri'], ], ]; diff --git a/plugins/ActivityPub/Entity/ActivitypubActor.php b/plugins/ActivityPub/Entity/ActivitypubActor.php index e30dec0285..a1659cea9b 100644 --- a/plugins/ActivityPub/Entity/ActivitypubActor.php +++ b/plugins/ActivityPub/Entity/ActivitypubActor.php @@ -1,6 +1,6 @@ * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -33,6 +34,7 @@ namespace Plugin\ActivityPub\Entity; use App\Core\Cache; use App\Core\Entity; +use function App\Core\I18n\_m; use App\Core\Log; use App\Entity\Actor; use Component\FreeNetwork\Util\Discovery; @@ -41,9 +43,6 @@ use Exception; use Plugin\ActivityPub\Util\DiscoveryHints; use Plugin\ActivityPub\Util\Explorer; use XML_XRD; -use function App\Core\I18n\_m; -use function array_key_exists; -use function is_null; /** * Table Definition for activitypub_actor @@ -158,10 +157,10 @@ class ActivitypubActor extends Entity $addr = Discovery::normalize($addr); // Try the cache - $uri = Cache::get(sprintf('ActivitypubActor-webfinger-%s', urlencode($addr)), fn() => false); + $uri = Cache::get(sprintf('ActivitypubActor-webfinger-%s', urlencode($addr)), fn () => false); if ($uri !== false) { - if (is_null($uri)) { + if (\is_null($uri)) { // TRANS: Exception. throw new Exception(_m('Not a valid WebFinger address (via cache).')); } @@ -197,7 +196,7 @@ class ActivitypubActor extends Entity DiscoveryHints::fromXRD($xrd), ); - if (array_key_exists('activitypub', $hints)) { + if (\array_key_exists('activitypub', $hints)) { $uri = $hints['activitypub']; try { LOG::info("Discovery on acct:{$addr} with URI:{$uri}"); @@ -240,9 +239,7 @@ class ActivitypubActor extends Entity /** * @param ActivitypubActor $ap_actor - * @param Actor $actor - * @param ActivitypubRsa $activitypub_rsa - * @param string $res + * * @throws Exception */ public static function update_profile(self &$ap_actor, Actor &$actor, ActivitypubRsa &$activitypub_rsa, string $res): void @@ -253,17 +250,17 @@ class ActivitypubActor extends Entity public static function schemaDef(): array { return [ - 'name' => 'activitypub_actor', + 'name' => 'activitypub_actor', 'fields' => [ - 'uri' => ['type' => 'text', 'not null' => true], - 'actor_id' => ['type' => 'int', 'not null' => true], - 'inbox_uri' => ['type' => 'text', 'not null' => true], + 'uri' => ['type' => 'text', 'not null' => true], + 'actor_id' => ['type' => 'int', 'not null' => true], + 'inbox_uri' => ['type' => 'text', 'not null' => true], 'inbox_shared_uri' => ['type' => 'text'], - 'url' => ['type' => 'text'], - 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], - 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], + 'url' => ['type' => 'text'], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], + 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], - 'primary key' => ['actor_id'], + 'primary key' => ['actor_id'], 'foreign keys' => [ 'activitypub_actor_actor_id_fkey' => ['actor', ['actor_id' => 'id']], ], diff --git a/plugins/ActivityPub/Entity/ActivitypubObject.php b/plugins/ActivityPub/Entity/ActivitypubObject.php index cb2c61f675..cdccdac441 100644 --- a/plugins/ActivityPub/Entity/ActivitypubObject.php +++ b/plugins/ActivityPub/Entity/ActivitypubObject.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -117,16 +118,16 @@ class ActivitypubObject extends Entity public static function schemaDef(): array { return [ - 'name' => 'activitypub_object', + 'name' => 'activitypub_object', 'fields' => [ - 'object_uri' => ['type' => 'text', 'not null' => true, 'description' => 'Object\'s URI'], + 'object_uri' => ['type' => 'text', 'not null' => true, 'description' => 'Object\'s URI'], 'object_type' => ['type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'the name of the table this object refers to'], - 'object_id' => ['type' => 'int', 'not null' => true, 'description' => 'id in the referenced table'], - 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], - 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], + 'object_id' => ['type' => 'int', 'not null' => true, 'description' => 'id in the referenced table'], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], + 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], 'primary key' => ['object_uri'], - 'indexes' => [ + 'indexes' => [ 'activity_object_uri_idx' => ['object_uri'], ], ]; diff --git a/plugins/ActivityPub/Entity/ActivitypubRsa.php b/plugins/ActivityPub/Entity/ActivitypubRsa.php index 0faafef15a..a0b3098cf5 100644 --- a/plugins/ActivityPub/Entity/ActivitypubRsa.php +++ b/plugins/ActivityPub/Entity/ActivitypubRsa.php @@ -1,6 +1,6 @@ * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -119,15 +120,15 @@ class ActivitypubRsa extends Entity public static function schemaDef(): array { return [ - 'name' => 'activitypub_rsa', + 'name' => 'activitypub_rsa', 'fields' => [ - 'actor_id' => ['type' => 'int', 'not null' => true], + 'actor_id' => ['type' => 'int', 'not null' => true], 'private_key' => ['type' => 'text'], - 'public_key' => ['type' => 'text', 'not null' => true], - 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], - 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], + 'public_key' => ['type' => 'text', 'not null' => true], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], + 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], - 'primary key' => ['actor_id'], + 'primary key' => ['actor_id'], 'foreign keys' => [ 'activitypub_rsa_actor_id_fkey' => ['actor', ['actor_id' => 'id']], ], @@ -137,27 +138,28 @@ class ActivitypubRsa extends Entity /** * Guarantees RSA keys for a given actor. * - * @param Actor $gsactor * @param bool $fetch =true Should attempt to fetch keys from a remote profile? - * @return ActivitypubRsa The keys (private key is null for remote actors) + * * @throws ServerException It should never occur, but if so, we break everything! + * + * @return ActivitypubRsa The keys (private key is null for remote actors) */ public static function getByActor(Actor $gsactor, bool $fetch = true): self { $apRSA = self::getByPK(['actor_id' => ($actor_id = $gsactor->getId())]); - if (is_null($apRSA)) { + if (\is_null($apRSA)) { // Nonexistent key pair for this profile if ($gsactor->getIsLocal()) { self::generateKeys($private_key, $public_key); $apRSA = self::create([ - 'actor_id' => $actor_id, + 'actor_id' => $actor_id, 'private_key' => $private_key, - 'public_key' => $public_key, + 'public_key' => $public_key, ]); - DB::wrapInTransaction(fn() => DB::persist($apRSA)); + DB::wrapInTransaction(fn () => DB::persist($apRSA)); } else { // ASSERT: This should never happen, but try to recover! - Log::error("Activitypub_rsa: An impossible thing has happened... Please let the devs know."); + Log::error('Activitypub_rsa: An impossible thing has happened... Please let the devs know.'); if ($fetch) { //$res = Activitypub_explorer::get_remote_user_activity($profile->getUri()); //Activitypub_rsa::update_public_key($profile, $res['publicKey']['publicKeyPem']); @@ -173,16 +175,17 @@ class ActivitypubRsa extends Entity /** * Generates a pair of RSA keys. * - * @param string|null $private_key out - * @param string|null $public_key out + * @param null|string $private_key out + * @param null|string $public_key out + * * @author PHP Manual Contributed Notes */ private static function generateKeys(?string &$private_key, ?string &$public_key): void { $config = [ - 'digest_alg' => 'sha512', + 'digest_alg' => 'sha512', 'private_key_bits' => 2048, - 'private_key_type' => OPENSSL_KEYTYPE_RSA, + 'private_key_type' => \OPENSSL_KEYTYPE_RSA, ]; // Create the private and public key @@ -192,8 +195,8 @@ class ActivitypubRsa extends Entity openssl_pkey_export($res, $private_key); // Extract the public key from $res to $pubKey - $pubKey = openssl_pkey_get_details($res); - $public_key = $pubKey["key"]; + $pubKey = openssl_pkey_get_details($res); + $public_key = $pubKey['key']; unset($pubKey); } } diff --git a/plugins/ActivityPub/Util/DiscoveryHints.php b/plugins/ActivityPub/Util/DiscoveryHints.php index f00cd70678..d8b083c548 100644 --- a/plugins/ActivityPub/Util/DiscoveryHints.php +++ b/plugins/ActivityPub/Util/DiscoveryHints.php @@ -1,6 +1,6 @@ * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -51,7 +52,6 @@ use XML_XRD; /** * DiscoveryHints implementation for GNU social * - * * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ @@ -59,9 +59,6 @@ class DiscoveryHints { /** * Search the WebFinger XRD after an ActivityPub URI - * - * @param XML_XRD $xrd - * @return array */ public static function fromXRD(XML_XRD $xrd): array { @@ -79,4 +76,4 @@ class DiscoveryHints return $hints; } -} \ No newline at end of file +} diff --git a/plugins/ActivityPub/Util/Explorer.php b/plugins/ActivityPub/Util/Explorer.php index b9a231883b..80b0f217b6 100644 --- a/plugins/ActivityPub/Util/Explorer.php +++ b/plugins/ActivityPub/Util/Explorer.php @@ -1,6 +1,6 @@ * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -35,15 +36,13 @@ use App\Core\HTTPClient; use App\Core\Log; use App\Util\Exception\NoSuchActorException; use Exception; +use const JSON_UNESCAPED_SLASHES; use Plugin\ActivityPub\ActivityPub; use Plugin\ActivityPub\Entity\ActivitypubActor; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; -use function in_array; -use function is_null; -use const JSON_UNESCAPED_SLASHES; /** * ActivityPub's own Explorer @@ -60,10 +59,8 @@ class Explorer /** * Shortcut function to get a single profile from its URL. * - * @param string $url * @param bool $grab_online whether to try online grabbing, defaults to true * - * @return ActivitypubActor * @throws ClientExceptionInterface * @throws NoSuchActorException * @throws RedirectionExceptionInterface @@ -86,8 +83,8 @@ class Explorer * This function cleans the $this->discovered_actor_profiles array * so that there is no erroneous data * - * @param string $url User's url - * @param bool $grab_online whether to try online grabbing, defaults to true + * @param string $url User's url + * @param bool $grab_online whether to try online grabbing, defaults to true * * @throws ClientExceptionInterface * @throws NoSuchActorException @@ -99,7 +96,7 @@ class Explorer */ public function lookup(string $url, bool $grab_online = true) { - if (in_array($url, ActivityPub::PUBLIC_TO)) { + if (\in_array($url, ActivityPub::PUBLIC_TO)) { return []; } @@ -114,8 +111,8 @@ class Explorer * This is a recursive function that will accumulate the results on * $discovered_actor_profiles array * - * @param string $url User's url - * @param bool $grab_online whether to try online grabbing, defaults to true + * @param string $url User's url + * @param bool $grab_online whether to try online grabbing, defaults to true * * @throws ClientExceptionInterface * @throws NoSuchActorException @@ -187,13 +184,13 @@ class Explorer { Log::debug('ActivityPub Explorer: Trying to grab a remote actor for ' . $url); $response = HTTPClient::get($url, ['headers' => ACTIVITYPUB::HTTP_CLIENT_HEADERS]); - $res = json_decode($response->getContent(), true); + $res = json_decode($response->getContent(), true); if ($response->getStatusCode() == 410) { // If it was deleted return true; // Nothing to add. } elseif (!HTTPClient::statusCodeIsOkay($response)) { // If it is unavailable return false; // Try to add at another time. } - if (is_null($res)) { + if (\is_null($res)) { Log::debug('ActivityPub Explorer: Invalid response returned from given Actor URL: ' . $res); return true; // Nothing to add. } @@ -210,7 +207,7 @@ class Explorer Log::debug( 'ActivityPub Explorer: Invalid potential remote actor while grabbing remotely: ' . $url . '. He returned the following: ' . json_encode($res, JSON_UNESCAPED_SLASHES) - . ' and the following exception: ' . $e->getMessage() + . ' and the following exception: ' . $e->getMessage(), ); return false; } @@ -229,14 +226,12 @@ class Explorer public static function get_aprofile_by_url(string $v): ActivitypubActor|bool { $aprofile = ActivitypubActor::getByPK(['uri' => $v]); - return is_null($aprofile) ? false : ActivitypubActor::getByPK(['uri' => $v]); + return \is_null($aprofile) ? false : ActivitypubActor::getByPK(['uri' => $v]); } /** * Allows the Explorer to transverse a collection of persons. * - * @param string $url - * @return bool * @throws ClientExceptionInterface * @throws NoSuchActorException * @throws RedirectionExceptionInterface @@ -246,7 +241,7 @@ class Explorer private function travel_collection(string $url): bool { $response = HTTPClient::get($url, ['headers' => ACTIVITYPUB::HTTP_CLIENT_HEADERS]); - $res = json_decode($response->getContent(), true); + $res = json_decode($response->getContent(), true); if (!isset($res['orderedItems'])) { return false; @@ -258,7 +253,7 @@ class Explorer } } // Go through entire collection - if (!is_null($res['next'])) { + if (!\is_null($res['next'])) { $this->travel_collection($res['next']); } @@ -272,12 +267,12 @@ class Explorer * @param string $url User's url * * @throws ClientExceptionInterface + * @throws Exception * @throws RedirectionExceptionInterface * @throws ServerExceptionInterface * @throws TransportExceptionInterface - * @throws Exception * - * @return string|null If it is able to fetch, false if it's gone + * @return null|string If it is able to fetch, false if it's gone * // Exceptions when network issues or unsupported Activity format */ public static function get_remote_user_activity(string $url): string|null diff --git a/plugins/ActivityPub/Util/HTTPSignature.php b/plugins/ActivityPub/Util/HTTPSignature.php index 9a358648f4..ebfea0fbb6 100644 --- a/plugins/ActivityPub/Util/HTTPSignature.php +++ b/plugins/ActivityPub/Util/HTTPSignature.php @@ -1,6 +1,6 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 - * @link https://github.com/aaronpk/Nautilus/blob/master/app/ActivityPub/HTTPSignature.php + * + * @see https://github.com/aaronpk/Nautilus/blob/master/app/ActivityPub/HTTPSignature.php */ namespace Plugin\ActivityPub\Util; @@ -34,12 +36,14 @@ class HTTPSignature /** * Sign a message with an Actor * - * @param Actor $user Actor signing - * @param string $url Inbox url - * @param string|bool $body Data to sign (optional) - * @param array $addlHeaders Additional headers (optional) - * @return array Headers to be used in request + * @param Actor $user Actor signing + * @param string $url Inbox url + * @param bool|string $body Data to sign (optional) + * @param array $addlHeaders Additional headers (optional) + * * @throws Exception Attempted to sign something that belongs to an Actor we don't own + * + * @return array Headers to be used in request */ public static function sign(Actor $user, string $url, string|bool $body = false, array $addlHeaders = []): array { @@ -47,15 +51,15 @@ class HTTPSignature if ($body) { $digest = self::_digest($body); } - $headers = self::_headersToSign($url, $digest); - $headers = array_merge($headers, $addlHeaders); - $stringToSign = self::_headersToSigningString($headers); - $signedHeaders = implode(' ', array_map('strtolower', array_keys($headers))); + $headers = self::_headersToSign($url, $digest); + $headers = array_merge($headers, $addlHeaders); + $stringToSign = self::_headersToSigningString($headers); + $signedHeaders = implode(' ', array_map('strtolower', array_keys($headers))); $actor_private_key = ActivitypubRsa::getByActor($user)->getPrivateKey(); // Intentionally unhandled exception, we want this to explode if that happens as it would be a bug $key = openssl_pkey_get_private($actor_private_key); - openssl_sign($stringToSign, $signature, $key, OPENSSL_ALGO_SHA256); - $signature = base64_encode($signature); + openssl_sign($stringToSign, $signature, $key, \OPENSSL_ALGO_SHA256); + $signature = base64_encode($signature); $signatureHeader = 'keyId="' . $user->getUri() . '#public-key' . '",headers="' . $signedHeaders . '",algorithm="rsa-sha256",signature="' . $signature . '"'; unset($headers['(request-target)']); $headers['Signature'] = $signatureHeader; @@ -65,20 +69,16 @@ class HTTPSignature /** * @param array|string $body array or json string $body - * @return string */ private static function _digest(array|string $body): string { - if (is_array($body)) { + if (\is_array($body)) { $body = json_encode($body); } return base64_encode(hash('sha256', $body, true)); } /** - * @param string $url - * @param string|bool $digest - * @return array * @throws Exception */ protected static function _headersToSign(string $url, string|bool $digest = false): array @@ -86,12 +86,12 @@ class HTTPSignature $date = new DateTime('UTC'); $headers = [ - '(request-target)' => 'post ' . parse_url($url, PHP_URL_PATH), - 'Date' => $date->format('D, d M Y H:i:s \G\M\T'), - 'Host' => parse_url($url, PHP_URL_HOST), - 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams", application/activity+json, application/json', - 'User-Agent' => 'GNU social ActivityPub Plugin - ' . GNUSOCIAL_ENGINE_URL, - 'Content-Type' => 'application/activity+json' + '(request-target)' => 'post ' . parse_url($url, \PHP_URL_PATH), + 'Date' => $date->format('D, d M Y H:i:s \G\M\T'), + 'Host' => parse_url($url, \PHP_URL_HOST), + 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams", application/activity+json, application/json', + 'User-Agent' => 'GNU social ActivityPub Plugin - ' . GNUSOCIAL_ENGINE_URL, + 'Content-Type' => 'application/activity+json', ]; if ($digest) { @@ -101,24 +101,14 @@ class HTTPSignature return $headers; } - /** - * @param array $headers - * @return string - */ private static function _headersToSigningString(array $headers): string { - return implode("\n", array_map(function ($k, $v) { - return strtolower($k) . ': ' . $v; - }, array_keys($headers), $headers)); + return implode("\n", array_map(fn ($k, $v) => mb_strtolower($k) . ': ' . $v, array_keys($headers), $headers)); } - /** - * @param string $signature - * @return array - */ public static function parseSignatureHeader(string $signature): array { - $parts = explode(',', $signature); + $parts = explode(',', $signature); $signatureData = []; foreach ($parts as $part) { @@ -129,51 +119,43 @@ class HTTPSignature if (!isset($signatureData['keyId'])) { return [ - 'error' => 'No keyId was found in the signature header. Found: ' . implode(', ', array_keys($signatureData)) + 'error' => 'No keyId was found in the signature header. Found: ' . implode(', ', array_keys($signatureData)), ]; } - if (!filter_var($signatureData['keyId'], FILTER_VALIDATE_URL)) { + if (!filter_var($signatureData['keyId'], \FILTER_VALIDATE_URL)) { return [ - 'error' => 'keyId is not a URL: ' . $signatureData['keyId'] + 'error' => 'keyId is not a URL: ' . $signatureData['keyId'], ]; } if (!isset($signatureData['headers']) || !isset($signatureData['signature'])) { return [ - 'error' => 'Signature is missing headers or signature parts' + 'error' => 'Signature is missing headers or signature parts', ]; } return $signatureData; } - /** - * @param string $publicKey - * @param array $signatureData - * @param array $inputHeaders - * @param string $path - * @param string $body - * @return array - */ public static function verify(string $publicKey, array $signatureData, array $inputHeaders, string $path, string $body): array { // We need this because the used Request headers fields specified by Signature are in lower case. - $headersContent = array_change_key_case($inputHeaders, CASE_LOWER); - $digest = 'SHA-256=' . base64_encode(hash('sha256', $body, true)); - $headersToSign = []; + $headersContent = array_change_key_case($inputHeaders, \CASE_LOWER); + $digest = 'SHA-256=' . base64_encode(hash('sha256', $body, true)); + $headersToSign = []; foreach (explode(' ', $signatureData['headers']) as $h) { if ($h == '(request-target)') { $headersToSign[$h] = 'post ' . $path; } elseif ($h == 'digest') { $headersToSign[$h] = $digest; - } elseif (array_key_exists($h, $headersContent)) { + } elseif (\array_key_exists($h, $headersContent)) { $headersToSign[$h] = $headersContent[$h]; } } $signingString = self::_headersToSigningString($headersToSign); - $verified = openssl_verify($signingString, base64_decode($signatureData['signature']), $publicKey, OPENSSL_ALGO_SHA256); + $verified = openssl_verify($signingString, base64_decode($signatureData['signature']), $publicKey, \OPENSSL_ALGO_SHA256); return [$verified, $signingString]; } diff --git a/plugins/ActivityPub/Util/Model.php b/plugins/ActivityPub/Util/Model.php index 327309b9f3..679857d250 100644 --- a/plugins/ActivityPub/Util/Model.php +++ b/plugins/ActivityPub/Util/Model.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -53,29 +54,27 @@ abstract class Model /** * Create a Type from an ActivityStreams 2.0 JSON string * - * @param string|array $data - * @return Type\AbstractObject * @throws Exception */ public static function jsonToType(string|array $data): Type\AbstractObject { - if (is_string($data)) { + if (\is_string($data)) { $attributes = json_decode($data, true); - if (json_last_error() !== JSON_ERROR_NONE - || !is_array($attributes) + if (json_last_error() !== \JSON_ERROR_NONE + || !\is_array($attributes) ) { throw new Exception( sprintf( "An error occurred during the JSON decoding.\n '%s'", - $data - ) + $data, + ), ); } } else { $attributes = $data; } - if (!array_key_exists('type', $attributes)) { + if (!\array_key_exists('type', $attributes)) { throw new InvalidArgumentException('Missing "type" attribute in $data: ' . var_export($data, true)); } unset($data); @@ -83,13 +82,13 @@ abstract class Model try { $type = TypeResolver::getClass($attributes['type']); } catch (Exception $e) { - $message = json_encode($attributes, JSON_PRETTY_PRINT); + $message = json_encode($attributes, \JSON_PRETTY_PRINT); throw new Exception( - $e->getMessage() . "\n$message" + $e->getMessage() . "\n{$message}", ); } - if (is_string($type)) { + if (\is_string($type)) { $type = new $type(); } @@ -112,22 +111,17 @@ abstract class Model /** * Create an Entity from an ActivityStreams 2.0 JSON string - * - * @param string|Type\AbstractObject $json - * @param array $options - * @return Entity */ abstract public static function fromJson(string|Type\AbstractObject $json, array $options = []): Entity; /** * Get a JSON * - * @param mixed $object - * @param ?int $options PHP JSON options - * @return string + * @param ?int $options PHP JSON options + * * @throws ClientException */ - public static function toJson(mixed $object, int $options = null): string + public static function toJson(mixed $object, ?int $options = null): string { switch ($object::class) { case 'App\Entity\Activity': @@ -140,4 +134,4 @@ abstract class Model return $type->toJson($options); } } -} \ No newline at end of file +} diff --git a/plugins/ActivityPub/Util/Model/Activity.php b/plugins/ActivityPub/Util/Model/Activity.php index 5e26e9bd91..170e9446f3 100644 --- a/plugins/ActivityPub/Util/Model/Activity.php +++ b/plugins/ActivityPub/Util/Model/Activity.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -63,29 +64,26 @@ class Activity extends Model * Create an Entity from an ActivityStreams 2.0 JSON string * This will persist new GSActivities, GSObjects, and APActivity * - * @param string|AbstractObject $json - * @param array $options - * @return ActivitypubActivity - * @throws NoSuchActorException * @throws ClientExceptionInterface + * @throws NoSuchActorException * @throws RedirectionExceptionInterface * @throws ServerExceptionInterface * @throws TransportExceptionInterface */ public static function fromJson(string|AbstractObject $json, array $options = []): ActivitypubActivity { - $type_activity = is_string($json) ? self::jsonToType($json) : $json; + $type_activity = \is_string($json) ? self::jsonToType($json) : $json; // Ditch known activities $ap_act = ActivitypubActivity::getByPK(['activity_uri' => $type_activity->get('id')]); - if (!is_null($ap_act)) { + if (!\is_null($ap_act)) { return $ap_act; } // Find Actor and Object - $actor = ActivityPub::getActorByUri($type_activity->get('actor')); + $actor = ActivityPub::getActorByUri($type_activity->get('actor')); $type_object = $type_activity->get('object'); - if (is_string($type_object)) { // Retrieve it + if (\is_string($type_object)) { // Retrieve it $type_object = ActivityPub::getObjectByUri($type_object, try_online: true); } else { // Encapsulated, if we have it locally, prefer it $type_object = ActivityPub::getObjectByUri($type_object->get('id'), try_online: false) ?? $type_object; @@ -118,20 +116,20 @@ class Activity extends Model } // Store Activity $act = GSActivity::create([ - 'actor_id' => $actor->getId(), - 'verb' => 'create', + 'actor_id' => $actor->getId(), + 'verb' => 'create', 'object_type' => 'note', - 'object_id' => $note->getId(), - 'created' => new DateTime($type_activity->get('published') ?? 'now'), - 'source' => 'ActivityPub', + 'object_id' => $note->getId(), + 'created' => new DateTime($type_activity->get('published') ?? 'now'), + 'source' => 'ActivityPub', ]); DB::persist($act); // Store ActivityPub Activity $ap_act = ActivitypubActivity::create([ - 'activity_id' => $act->getId(), + 'activity_id' => $act->getId(), 'activity_uri' => $type_activity->get('id'), - 'created' => new DateTime($type_activity->get('published') ?? 'now'), - 'modified' => new DateTime(), + 'created' => new DateTime($type_activity->get('published') ?? 'now'), + 'modified' => new DateTime(), ]); DB::persist($ap_act); } @@ -141,9 +139,6 @@ class Activity extends Model /** * Get a JSON * - * @param mixed $object - * @param int|null $options - * @return string * @throws ClientException */ public static function toJson(mixed $object, ?int $options = null): string @@ -151,24 +146,24 @@ class Activity extends Model if ($object::class !== 'App\Entity\Activity') { throw new InvalidArgumentException('First argument type is Activity'); } - - $gs_verb_to_activity_stream_two_verb = null; - if (Event::handle('GSVerbToActivityStreamsTwoActivityType', [($verb = $object->getVerb()), &$gs_verb_to_activity_stream_two_verb]) === Event::next) { - $gs_verb_to_activity_stream_two_verb = match ($verb) { - 'create' => 'Create', - 'undo' => 'Undo', - default => throw new ClientException('Invalid verb'), - }; - } + + $gs_verb_to_activity_stream_two_verb = null; + if (Event::handle('GSVerbToActivityStreamsTwoActivityType', [($verb = $object->getVerb()), &$gs_verb_to_activity_stream_two_verb]) === Event::next) { + $gs_verb_to_activity_stream_two_verb = match ($verb) { + 'create' => 'Create', + 'undo' => 'Undo', + default => throw new ClientException('Invalid verb'), + }; + } $attr = [ - 'type' => $gs_verb_to_activity_stream_two_verb, - '@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => Router::url('activity_view', ['id' => $object->getId()], Router::ABSOLUTE_URL), + 'type' => $gs_verb_to_activity_stream_two_verb, + '@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => Router::url('activity_view', ['id' => $object->getId()], Router::ABSOLUTE_URL), 'published' => $object->getCreated()->format(DateTimeInterface::RFC3339), - 'actor' => $object->getActor()->getUri(Router::ABSOLUTE_URL), - 'to' => ['https://www.w3.org/ns/activitystreams#Public'], // TODO: implement proper scope address - 'cc' => ['https://www.w3.org/ns/activitystreams#Public'], + 'actor' => $object->getActor()->getUri(Router::ABSOLUTE_URL), + 'to' => ['https://www.w3.org/ns/activitystreams#Public'], // TODO: implement proper scope address + 'cc' => ['https://www.w3.org/ns/activitystreams#Public'], ]; $attr['object'] = ($attr['type'] === 'Create') ? self::jsonToType(Model::toJson($object->getObject())) : ActivityPub::getUriByObject($object->getObject()); diff --git a/plugins/ActivityPub/Util/Model/Actor.php b/plugins/ActivityPub/Util/Model/Actor.php index a8f2b927d9..c5c38907c2 100644 --- a/plugins/ActivityPub/Util/Model/Actor.php +++ b/plugins/ActivityPub/Util/Model/Actor.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -60,29 +61,25 @@ use Plugin\ActivityPub\Util\Model; */ class Actor extends Model { - /** * Create an Entity from an ActivityStreams 2.0 JSON string * This will persist a new GSActor, ActivityPubRSA, and ActivityPubActor * - * @param string|AbstractObject $json - * @param array $options - * @return ActivitypubActor * @throws Exception */ public static function fromJson(string|AbstractObject $json, array $options = []): ActivitypubActor { - $person = is_string($json) ? self::jsonToType($json) : $json; + $person = \is_string($json) ? self::jsonToType($json) : $json; // Actor $actor_map = [ 'nickname' => $person->get('preferredUsername'), 'fullname' => !empty($person->get('name')) ? $person->get('name') : null, - 'created' => new DateTime($person->get('published') ?? 'now'), - 'bio' => $person->get('summary'), + 'created' => new DateTime($person->get('published') ?? 'now'), + 'bio' => $person->get('summary'), 'is_local' => false, - 'type' => GSActor::PERSON, - 'roles' => UserRoles::USER, + 'type' => GSActor::PERSON, + 'roles' => UserRoles::USER, 'modified' => new DateTime(), ]; @@ -99,11 +96,11 @@ class Actor extends Model // ActivityPub Actor $ap_actor = ActivitypubActor::create([ - 'inbox_uri' => $person->get('inbox'), + 'inbox_uri' => $person->get('inbox'), 'inbox_shared_uri' => ($person->has('endpoints') && isset($person->get('endpoints')['sharedInbox'])) ? $person->get('endpoints')['sharedInbox'] : null, - 'uri' => $person->get('id'), - 'actor_id' => $actor->getId(), - 'url' => $person->get('url') ?? null, + 'uri' => $person->get('id'), + 'actor_id' => $actor->getId(), + 'url' => $person->get('url') ?? null, ], $options['objects']['ActivitypubActor'] ?? null); if (!isset($options['objects']['ActivitypubActor'])) { @@ -112,7 +109,7 @@ class Actor extends Model // Public Key $apRSA = ActivitypubRsa::create([ - 'actor_id' => $actor->getID(), + 'actor_id' => $actor->getID(), 'public_key' => ($person->has('publicKey') && isset($person->get('publicKey')['publicKeyPem'])) ? $person->get('publicKey')['publicKeyPem'] : null, ], $options['objects']['ActivitypubRsa'] ?? null); @@ -125,8 +122,8 @@ class Actor extends Model try { // Retrieve media $get_response = HTTPClient::get($person->get('icon')->get('url')); - $media = $get_response->getContent(); - $mimetype = $get_response->getHeaders()['content-type'][0] ?? null; + $media = $get_response->getContent(); + $mimetype = $get_response->getHeaders()['content-type'][0] ?? null; unset($get_response); // Only handle if it is an image @@ -168,9 +165,8 @@ class Actor extends Model /** * Get a JSON * - * @param mixed $object - * @param int|null $options PHP JSON options - * @return string + * @param null|int $options PHP JSON options + * * @throws ServerException */ public static function toJson(mixed $object, ?int $options = null): string @@ -178,41 +174,41 @@ class Actor extends Model if ($object::class !== 'App\Entity\Actor') { throw new InvalidArgumentException('First argument type is Actor'); } - $rsa = ActivitypubRsa::getByActor($object); + $rsa = ActivitypubRsa::getByActor($object); $public_key = $rsa->getPublicKey(); - $uri = null; - $attr = [ - '@context' => 'https://www.w3.org/ns/activitystreams', - 'type' => 'Person', - 'id' => $object->getUri(Router::ABSOLUTE_URL), - 'inbox' => Router::url('activitypub_actor_inbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL), - 'outbox' => Router::url('activitypub_actor_outbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL), + $uri = null; + $attr = [ + '@context' => 'https://www.w3.org/ns/activitystreams', + 'type' => 'Person', + 'id' => $object->getUri(Router::ABSOLUTE_URL), + 'inbox' => Router::url('activitypub_actor_inbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL), + 'outbox' => Router::url('activitypub_actor_outbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL), 'following' => Router::url('actor_subscriptions_id', ['id' => $object->getId()], Router::ABSOLUTE_URL), 'followers' => Router::url('actor_subscribers_id', ['id' => $object->getId()], Router::ABSOLUTE_URL), - 'liked' => Router::url('favourites_view_by_actor_id', ['id' => $object->getId()], Router::ABSOLUTE_URL), + 'liked' => Router::url('favourites_view_by_actor_id', ['id' => $object->getId()], Router::ABSOLUTE_URL), //'streams' => 'preferredUsername' => $object->getNickname(), - 'publicKey' => [ - 'id' => $uri . "#public-key", - 'owner' => $uri, - 'publicKeyPem' => $public_key + 'publicKey' => [ + 'id' => $uri . '#public-key', + 'owner' => $uri, + 'publicKeyPem' => $public_key, ], - 'name' => $object->getFullname(), - 'location' => $object->getLocation(), + 'name' => $object->getFullname(), + 'location' => $object->getLocation(), 'published' => $object->getCreated()->format(DateTimeInterface::RFC3339), - 'summary' => $object->getBio(), + 'summary' => $object->getBio(), //'tag' => $object->getSelfTags(), 'updated' => $object->getModified()->format(DateTimeInterface::RFC3339), - 'url' => $object->getUrl(Router::ABSOLUTE_URL), + 'url' => $object->getUrl(Router::ABSOLUTE_URL), ]; // Avatar try { - $avatar = Avatar::getAvatar($object->getId()); + $avatar = Avatar::getAvatar($object->getId()); $attr['icon'] = $attr['image'] = [ - 'type' => 'Image', + 'type' => 'Image', 'mediaType' => $avatar->getAttachment()->getMimetype(), - 'url' => $avatar->getUrl(type: Router::ABSOLUTE_URL), + 'url' => $avatar->getUrl(type: Router::ABSOLUTE_URL), ]; } catch (Exception) { // No icon for this actor @@ -222,4 +218,4 @@ class Actor extends Model Event::handle('ActivityPubAddActivityStreamsTwoData', [$type->get('type'), &$type]); return $type->toJson($options); } -} \ No newline at end of file +} diff --git a/plugins/ActivityPub/Util/Model/Note.php b/plugins/ActivityPub/Util/Model/Note.php index 8e1beb0825..0ab47a6e24 100644 --- a/plugins/ActivityPub/Util/Model/Note.php +++ b/plugins/ActivityPub/Util/Model/Note.php @@ -39,11 +39,10 @@ use App\Core\DB\DB; use App\Core\Event; use App\Core\GSFile; use App\Core\HTTPClient; -use App\Core\VisibilityScope; -use Component\Language\Entity\Language; use function App\Core\I18n\_m; use App\Core\Log; use App\Core\Router\Router; +use App\Core\VisibilityScope; use App\Entity\Note as GSNote; use App\Entity\NoteTag; use App\Util\Common; @@ -56,11 +55,13 @@ use App\Util\TemporaryFile; use Component\Attachment\Entity\ActorToAttachment; use Component\Attachment\Entity\AttachmentToNote; use Component\Conversation\Conversation; +use Component\Language\Entity\Language; use Component\Tag\Tag; use DateTime; use DateTimeInterface; use Exception; use InvalidArgumentException; +use const PHP_URL_HOST; use Plugin\ActivityPub\ActivityPub; use Plugin\ActivityPub\Entity\ActivitypubObject; use Plugin\ActivityPub\Util\Model; @@ -68,10 +69,6 @@ use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; -use function array_key_exists; -use function is_null; -use function is_string; -use const PHP_URL_HOST; /** * This class handles translation between JSON and GSNotes @@ -98,7 +95,7 @@ class Note extends Model { $handleInReplyTo = function (AbstractObject|string $type_note): ?int { try { - $parent_note = is_null($type_note->get('inReplyTo')) ? null : ActivityPub::getObjectByUri($type_note->get('inReplyTo'), try_online: true); + $parent_note = \is_null($type_note->get('inReplyTo')) ? null : ActivityPub::getObjectByUri($type_note->get('inReplyTo'), try_online: true); if ($parent_note instanceof GSNote) { return $parent_note->getId(); } elseif ($parent_note instanceof Type\AbstractObject && $parent_note->get('type') === 'Note') { @@ -116,13 +113,13 @@ class Note extends Model }; $source = $options['source'] ?? 'ActivityPub'; - $type_note = is_string($json) ? self::jsonToType($json) : $json; + $type_note = \is_string($json) ? self::jsonToType($json) : $json; $actor = null; $actor_id = null; if ($json instanceof AbstractObject - && array_key_exists('test_authority', $options) + && \array_key_exists('test_authority', $options) && $options['test_authority'] - && array_key_exists('actor_uri', $options) + && \array_key_exists('actor_uri', $options) ) { $actor_uri = $options['actor_uri']; if ($actor_uri !== $type_note->get('attributedTo')) { @@ -135,7 +132,7 @@ class Note extends Model } } - if (is_null($actor_id)) { + if (\is_null($actor_id)) { $actor = ActivityPub::getActorByUri($type_note->get('attributedTo')); $actor_id = $actor->getId(); } @@ -164,14 +161,14 @@ class Note extends Model ]); } - if (!is_null($map['language_id'])) { + if (!\is_null($map['language_id'])) { $map['language_id'] = Language::getByLocale($map['language_id'])->getId(); } else { $map['language_id'] = null; } // Scope - if (in_array('https://www.w3.org/ns/activitystreams#Public', $type_note->get('to'))) { + if (\in_array('https://www.w3.org/ns/activitystreams#Public', $type_note->get('to'))) { // Public: Visible for all, shown in public feeds $map['scope'] = VisibilityScope::PUBLIC; } elseif (\in_array('https://www.w3.org/ns/activitystreams#Public', $type_note->get('cc'))) { @@ -258,7 +255,7 @@ class Note extends Model case 'Hashtag': $match = ltrim($ap_tag->get('name'), '#'); $tag = Tag::ensureValid($match); - $canonical_tag = $ap_tag->get('canonical') ?? Tag::canonicalTag($tag, is_null($lang_id = $obj->getLanguageId()) ? null : Language::getById($lang_id)->getLocale()); + $canonical_tag = $ap_tag->get('canonical') ?? Tag::canonicalTag($tag, \is_null($lang_id = $obj->getLanguageId()) ? null : Language::getById($lang_id)->getLocale()); DB::persist(NoteTag::create([ 'tag' => $tag, 'canonical' => $canonical_tag, @@ -323,7 +320,7 @@ class Note extends Model 'content' => $object->getRendered(), 'attachment' => [], 'tag' => [], - 'inReplyTo' => is_null($object->getReplyTo()) ? null : ActivityPub::getUriByObject(GSNote::getById($object->getReplyTo())), + 'inReplyTo' => \is_null($object->getReplyTo()) ? null : ActivityPub::getUriByObject(GSNote::getById($object->getReplyTo())), 'inConversation' => $object->getConversationUri(), 'directMessage' => $object->getScope() === VisibilityScope::MESSAGE, ]; diff --git a/plugins/ActivityPub/Util/ModelResponse.php b/plugins/ActivityPub/Util/ModelResponse.php index 13b9e61870..5e8d05e832 100644 --- a/plugins/ActivityPub/Util/ModelResponse.php +++ b/plugins/ActivityPub/Util/ModelResponse.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -43,8 +44,7 @@ abstract class ModelResponse * Provides a response in application/ld+json for ActivityStreams 2.0 Types * * @param mixed $object (Entity) - * @param int $status The response status code - * @return TypeResponse + * @param int $status The response status code */ public static function handle(mixed $object, int $status = 200): TypeResponse { diff --git a/plugins/ActivityPub/Util/ModelValidator.php b/plugins/ActivityPub/Util/ModelValidator.php index cc308e872b..d6ace73011 100644 --- a/plugins/ActivityPub/Util/ModelValidator.php +++ b/plugins/ActivityPub/Util/ModelValidator.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later diff --git a/plugins/ActivityPub/Util/Response/ActivityResponse.php b/plugins/ActivityPub/Util/Response/ActivityResponse.php index d5b72179cf..6e6e3a22be 100644 --- a/plugins/ActivityPub/Util/Response/ActivityResponse.php +++ b/plugins/ActivityPub/Util/Response/ActivityResponse.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -47,9 +48,8 @@ abstract class ActivityResponse /** * Provides a response in application/ld+json to GSActivity * - * @param GSActivity $activity * @param int $status The response status code - * @return TypeResponse + * * @throws ClientException */ public static function handle(GSActivity $activity, int $status = 200): TypeResponse diff --git a/plugins/ActivityPub/Util/Response/ActorResponse.php b/plugins/ActivityPub/Util/Response/ActorResponse.php index 06c1d920ef..dfeb0d1d06 100644 --- a/plugins/ActivityPub/Util/Response/ActorResponse.php +++ b/plugins/ActivityPub/Util/Response/ActorResponse.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -47,9 +48,8 @@ abstract class ActorResponse /** * Provides a response in application/ld+json to GSActors * - * @param GSActor $gsactor * @param int $status The response status code - * @return TypeResponse + * * @throws ClientException */ public static function handle(GSActor $gsactor, int $status = 200): TypeResponse diff --git a/plugins/ActivityPub/Util/Response/NoteResponse.php b/plugins/ActivityPub/Util/Response/NoteResponse.php index f800f065a0..c157a11edc 100644 --- a/plugins/ActivityPub/Util/Response/NoteResponse.php +++ b/plugins/ActivityPub/Util/Response/NoteResponse.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -46,9 +47,7 @@ abstract class NoteResponse /** * Provides a response in application/ld+json to GSNotes * - * @param GSNote $note * @param int $status The response status code - * @return TypeResponse */ public static function handle(GSNote $note, int $status = 200): TypeResponse { diff --git a/plugins/ActivityPub/Util/TypeResponse.php b/plugins/ActivityPub/Util/TypeResponse.php index 51cd68e054..45883096d4 100644 --- a/plugins/ActivityPub/Util/TypeResponse.php +++ b/plugins/ActivityPub/Util/TypeResponse.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -45,13 +46,13 @@ class TypeResponse extends JsonResponse /** * Provides a response in application/ld+json for ActivityStreams 2.0 Types * - * @param string|AbstractObject|null $json - * @param int $status The response status code + * @param null|AbstractObject|string $json + * @param int $status The response status code */ public function __construct(string|AbstractObject|null $json = null, int $status = 202) { parent::__construct( - data: is_object($json) ? $json->toJson() : $json, + data: \is_object($json) ? $json->toJson() : $json, status: $status, headers: ['content-type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'], json: true, diff --git a/plugins/ActivityPub/Util/Validator/contentLangModelValidator.php b/plugins/ActivityPub/Util/Validator/contentLangModelValidator.php index 659e851603..74c314d080 100644 --- a/plugins/ActivityPub/Util/Validator/contentLangModelValidator.php +++ b/plugins/ActivityPub/Util/Validator/contentLangModelValidator.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -49,8 +50,8 @@ class contentLangModelValidator extends ModelValidator * Validate manuallyApprovesFollowers value * * @param string $value - * @param mixed $container A Note - * @return bool + * @param mixed $container A Note + * * @throws Exception */ public function validate($value, $container): bool diff --git a/plugins/ActivityPub/Util/Validator/manuallyApprovesFollowersModelValidator.php b/plugins/ActivityPub/Util/Validator/manuallyApprovesFollowersModelValidator.php index 61f89ea5fe..94670c762a 100644 --- a/plugins/ActivityPub/Util/Validator/manuallyApprovesFollowersModelValidator.php +++ b/plugins/ActivityPub/Util/Validator/manuallyApprovesFollowersModelValidator.php @@ -1,6 +1,6 @@ * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later @@ -49,8 +50,8 @@ class manuallyApprovesFollowersModelValidator extends ModelValidator * Validate manuallyApprovesFollowers value * * @param string $value - * @param mixed $container A Person - * @return bool + * @param mixed $container A Person + * * @throws Exception */ public function validate($value, $container): bool diff --git a/plugins/AttachmentCollections/Controller/Controller.php b/plugins/AttachmentCollections/Controller/Controller.php index efd319c933..87e7814c89 100644 --- a/plugins/AttachmentCollections/Controller/Controller.php +++ b/plugins/AttachmentCollections/Controller/Controller.php @@ -23,16 +23,16 @@ declare(strict_types = 1); namespace Plugin\AttachmentCollections\Controller; -use App\Core\Form; use App\Core\DB\DB; -use App\Util\Common; -use App\Core\Router\Router; +use App\Core\Form; use function App\Core\I18n\_m; +use App\Core\Router\Router; +use App\Util\Common; use Component\Feed\Util\FeedController; -use Symfony\Component\HttpFoundation\Request; use Plugin\AttachmentCollections\Entity\Collection; -use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\HttpFoundation\Request; class Controller extends FeedController { @@ -47,16 +47,18 @@ class Controller extends FeedController } /** * Generate Collections page + * * @param int $id actor id * @param ?string $nickname actor nickname - * @return array twig template options + * + * @return array twig template options */ public function collectionsView(Request $request, int $id, ?string $nickname): array { $collections = DB::dql( 'select collection from Plugin\AttachmentCollections\Entity\Collection collection ' . 'where collection.actor_id = :id', - ['id' => $id] + ['id' => $id], ); // create collection form $create = null; @@ -64,9 +66,9 @@ class Controller extends FeedController $create = Form::create([ ['name', TextType::class, [ 'label' => _m('Create collection'), - 'attr' => [ + 'attr' => [ 'placeholder' => _m('Name'), - 'required' => 'required' + 'required' => 'required', ], 'data' => '', ]], @@ -80,7 +82,7 @@ class Controller extends FeedController $create->handleRequest($request); if ($create->isSubmitted() && $create->isValid()) { DB::persist(Collection::create([ - 'name' => $create->getData()['name'], + 'name' => $create->getData()['name'], 'actor_id' => $id, ])); DB::flush(); @@ -94,15 +96,14 @@ class Controller extends FeedController // Instead, I'm using an anonymous class to encapsulate // the functions and passing how the class to the template. // It's suggested at https://stackoverflow.com/a/50364502. - $fn = new class ($id, $nickname, $request) - { + $fn = new class($id, $nickname, $request) { private $id; private $nick; private $request; public function __construct($id, $nickname, $request) { - $this->id = $id; - $this->nick = $nickname; + $this->id = $id; + $this->nick = $nickname; $this->request = $request; } // there's already a injected function called path, @@ -114,12 +115,12 @@ class Controller extends FeedController if (\is_null($this->nick)) { return Router::url( 'collection_notes_view_by_actor_id', - ['id' => $this->id, 'cid' => $cid] + ['id' => $this->id, 'cid' => $cid], ); } return Router::url( 'collection_notes_view_by_nickname', - ['nickname' => $this->nick, 'cid' => $cid] + ['nickname' => $this->nick, 'cid' => $cid], ); } // There are many collections in this page and we need two @@ -133,11 +134,11 @@ class Controller extends FeedController ['name', TextType::class, [ 'attr' => [ 'placeholder' => 'New name', - 'required' => 'required' + 'required' => 'required', ], 'data' => '', ]], - ['update_'.$collection->getId(), SubmitType::class, [ + ['update_' . $collection->getId(), SubmitType::class, [ 'label' => _m('Save'), 'attr' => [ 'title' => _m('Save'), @@ -156,7 +157,7 @@ class Controller extends FeedController public function rmForm($collection) { $rm = Form::create([ - ['remove_'.$collection->getId(), SubmitType::class, [ + ['remove_' . $collection->getId(), SubmitType::class, [ 'label' => _m('Delete collection'), 'attr' => [ 'title' => _m('Delete collection'), @@ -190,12 +191,12 @@ class Controller extends FeedController public function collectionNotesByActorId(Request $request, int $id, int $cid): array { $collection = DB::findOneBy('attachment_collection', ['id' => $cid]); - $attchs = DB::dql( + $attchs = DB::dql( 'select attch from attachment_album_entry entry ' . 'left join Component\Attachment\Entity\Attachment attch ' . 'with entry.attachment_id = attch.id ' . 'where entry.collection_id = :cid', - ['cid' => $cid] + ['cid' => $cid], ); return [ '_template' => 'AttachmentCollections/collection.html.twig', diff --git a/plugins/AttachmentCollections/Entity/Collection.php b/plugins/AttachmentCollections/Entity/Collection.php index 1374bafe52..beb8772589 100644 --- a/plugins/AttachmentCollections/Entity/Collection.php +++ b/plugins/AttachmentCollections/Entity/Collection.php @@ -1,7 +1,11 @@ actor_id; } - // @codeCoverageIgnoreEnd // }}} Autocode - public static function schemaDef() { return [ 'name' => 'attachment_collection', 'fields' => [ 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'], - 'name' => ['type' => 'varchar', 'length' => 255, 'description' => 'collection\'s name'], + 'name' => ['type' => 'varchar', 'length' => 255, 'description' => 'collection\'s name'], 'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to many', 'not null' => true, 'description' => 'foreign key to actor table'], ], - 'primary key' => ['id'], + 'primary key' => ['id'], ]; } } - diff --git a/plugins/AttachmentCollections/Entity/CollectionEntry.php b/plugins/AttachmentCollections/Entity/CollectionEntry.php index 8ac4e3cdd5..0bee92d6e5 100644 --- a/plugins/AttachmentCollections/Entity/CollectionEntry.php +++ b/plugins/AttachmentCollections/Entity/CollectionEntry.php @@ -1,7 +1,11 @@ collection_id; } - // @codeCoverageIgnoreEnd // }}} Autocode - public static function schemaDef() { return [ @@ -62,4 +64,3 @@ class CollectionEntry extends Entity ]; } } - diff --git a/plugins/AudioEncoder/AudioEncoder.php b/plugins/AudioEncoder/AudioEncoder.php index 9ecca1cfda..67e4e014c7 100644 --- a/plugins/AudioEncoder/AudioEncoder.php +++ b/plugins/AudioEncoder/AudioEncoder.php @@ -1,6 +1,6 @@ exec('which ffmpeg'), + 'ffmpeg.binaries' => exec('which ffmpeg'), 'ffprobe.binaries' => exec('which ffprobe'), ]); $metadata = $ffprobe->streams($file->getRealPath()) // extracts streams informations - ->audios() // filters audios streams - ->first(); // returns the first audio stream - $width = (int)ceil((float)$metadata->get('duration')); + ->audios() // filters audios streams + ->first(); // returns the first audio stream + $width = (int) ceil((float) $metadata->get('duration')); return true; } @@ -100,7 +100,7 @@ class AudioEncoder extends Plugin 'audioEncoder/audioEncoderView.html.twig', [ 'attachment' => $vars['attachment'], - 'note' => $vars['note'], + 'note' => $vars['note'], ], ); return Event::stop; @@ -112,9 +112,9 @@ class AudioEncoder extends Plugin public function onPluginVersion(array &$versions): bool { $versions[] = [ - 'name' => 'AudioEncoder', - 'version' => self::version(), - 'author' => 'Diogo Peralta Cordeiro', + 'name' => 'AudioEncoder', + 'version' => self::version(), + 'author' => 'Diogo Peralta Cordeiro', 'rawdescription' => _m('Use PHP-FFMpeg for some more audio support.'), ]; return Event::next; diff --git a/plugins/Cover/Entity/Cover.php b/plugins/Cover/Entity/Cover.php index 85aba67c85..13350d918a 100644 --- a/plugins/Cover/Entity/Cover.php +++ b/plugins/Cover/Entity/Cover.php @@ -25,8 +25,8 @@ namespace Plugin\Cover\Entity; use App\Core\DB\DB; use App\Core\Entity; -use Component\Attachment\Entity\Attachment; use App\Util\Common; +use Component\Attachment\Entity\Attachment; use DateTimeInterface; /** diff --git a/plugins/Embed/Entity/AttachmentEmbed.php b/plugins/Embed/Entity/AttachmentEmbed.php index b87cf2c09e..cb8e118640 100644 --- a/plugins/Embed/Entity/AttachmentEmbed.php +++ b/plugins/Embed/Entity/AttachmentEmbed.php @@ -187,8 +187,8 @@ class AttachmentEmbed extends Entity $attr['has_attachment'] = false; } elseif (!\is_null($thumbnail)) { $attr['has_attachment'] = true; - $attr['width'] = $thumbnail->getWidth(); - $attr['height'] = $thumbnail->getHeight(); + $attr['width'] = $thumbnail->getWidth(); + $attr['height'] = $thumbnail->getHeight(); } return $attr; } diff --git a/plugins/ImageEncoder/ImageEncoder.php b/plugins/ImageEncoder/ImageEncoder.php index 5ff50dcece..55c966a530 100644 --- a/plugins/ImageEncoder/ImageEncoder.php +++ b/plugins/ImageEncoder/ImageEncoder.php @@ -55,7 +55,8 @@ class ImageEncoder extends Plugin return '3.0.0'; } - public static function shouldHandle (string $mimetype): bool { + public static function shouldHandle(string $mimetype): bool + { return GSFile::mimetypeMajor($mimetype) === 'image'; } diff --git a/plugins/Oomox/Controller/Oomox.php b/plugins/Oomox/Controller/Oomox.php index 1aa2a8e278..e2b2e6e0be 100644 --- a/plugins/Oomox/Controller/Oomox.php +++ b/plugins/Oomox/Controller/Oomox.php @@ -1,6 +1,6 @@ getColourForegroundLight() ?: '#09090d'; + $current_foreground = $current_oomox_settings->getColourForegroundLight() ?: '#09090d'; $current_background_hard = $current_oomox_settings->getColourBackgroundHardLight() ?: '#ebebeb'; $current_background_card = $current_oomox_settings->getColourBackgroundCardLight() ?: '#f0f0f0'; - $current_border = $current_oomox_settings->getColourBorderLight() ?: '#d5d5d5'; - $current_accent = $current_oomox_settings->getColourAccentLight() ?: '#a22430'; + $current_border = $current_oomox_settings->getColourBorderLight() ?: '#d5d5d5'; + $current_accent = $current_oomox_settings->getColourAccentLight() ?: '#a22430'; } else { - $current_foreground = $current_oomox_settings->getColourForegroundDark() ?: '#f0f6f6'; + $current_foreground = $current_oomox_settings->getColourForegroundDark() ?: '#f0f6f6'; $current_background_hard = $current_oomox_settings->getColourBackgroundHardDark() ?: '#141216'; $current_background_card = $current_oomox_settings->getColourBackgroundCardDark() ?: '#131217'; - $current_border = $current_oomox_settings->getColourBorderDark() ?: '#201f25'; - $current_accent = $current_oomox_settings->getColourAccentDark() ?: '#5ddbcf'; + $current_border = $current_oomox_settings->getColourBorderDark() ?: '#201f25'; + $current_accent = $current_oomox_settings->getColourAccentDark() ?: '#5ddbcf'; } } else { - $current_foreground = $is_light ? '#09090d' : '#f0f6f6'; + $current_foreground = $is_light ? '#09090d' : '#f0f6f6'; $current_background_hard = $is_light ? '#ebebeb' : '#141216'; $current_background_card = $is_light ? '#f0f0f0' : '#131217'; - $current_border = $is_light ? '#d5d5d5' : '#201f25'; - $current_accent = $is_light ? '#a22430' : '#5ddbcf'; + $current_border = $is_light ? '#d5d5d5' : '#201f25'; + $current_accent = $is_light ? '#a22430' : '#5ddbcf'; } return Form::create([ [$foreground, ColorType::class, [ 'html5' => true, - 'data' => $current_foreground, + 'data' => $current_foreground, 'label' => _m('Foreground colour'), - 'help' => _m('Choose the foreground colour'),], + 'help' => _m('Choose the foreground colour'), ], ], [$background_hard, ColorType::class, [ 'html5' => true, - 'data' => $current_background_hard, + 'data' => $current_background_hard, 'label' => _m('Background colour'), - 'help' => _m('Choose the background colour'),], + 'help' => _m('Choose the background colour'), ], ], [$background_card, ColorType::class, [ 'html5' => true, - 'data' => $current_background_card, + 'data' => $current_background_card, 'label' => _m('Card background colour'), - 'help' => _m('Choose the card background colour'),], + 'help' => _m('Choose the card background colour'), ], ], [$border, ColorType::class, [ 'html5' => true, - 'data' => $current_border, + 'data' => $current_border, 'label' => _m('Border colour'), - 'help' => _m('Choose the borders accents'),], + 'help' => _m('Choose the borders accents'), ], ], [$accent, ColorType::class, [ 'html5' => true, - 'data' => $current_accent, + 'data' => $current_accent, 'label' => _m('Accent colour'), - 'help' => _m('Choose the accent colour'),], + 'help' => _m('Choose the accent colour'), ], ], ['hidden', HiddenType::class, []], [$reset, SubmitType::class, ['label' => _m('Reset colours to default')]], @@ -141,11 +140,11 @@ class Oomox */ public static function oomoxSettingsLight(Request $request): array { - $user = Common::ensureLoggedIn(); + $user = Common::ensureLoggedIn(); $actor_id = $user->getId(); $current_oomox_settings = PluginOomox::getEntity($user); - $form_light = (new self)->getOomoxForm($current_oomox_settings, true); + $form_light = (new self)->getOomoxForm($current_oomox_settings, true); $form_light->handleRequest($request); if ($form_light->isSubmitted() && $form_light->isValid()) { @@ -156,15 +155,15 @@ class Oomox $current_oomox_settings?->resetTheme(true); } } else { - $data = $form_light->getData(); + $data = $form_light->getData(); $current_oomox_settings = EntityOomox::create( [ - 'actor_id' => $actor_id, - 'colour_foreground_light' => $data['colour_foreground_light'], + 'actor_id' => $actor_id, + 'colour_foreground_light' => $data['colour_foreground_light'], 'colour_background_hard_light' => $data['colour_background_hard_light'], 'colour_background_card_light' => $data['colour_background_card_light'], - 'colour_border_light' => $data['colour_border_light'], - 'colour_accent_light' => $data['colour_accent_light'], + 'colour_border_light' => $data['colour_border_light'], + 'colour_accent_light' => $data['colour_accent_light'], ], ); } @@ -187,11 +186,11 @@ class Oomox */ public static function oomoxSettingsDark(Request $request): array { - $user = Common::ensureLoggedIn(); + $user = Common::ensureLoggedIn(); $actor_id = $user->getId(); $current_oomox_settings = PluginOomox::getEntity($user); - $form_dark = (new self)->getOomoxForm($current_oomox_settings, false); + $form_dark = (new self)->getOomoxForm($current_oomox_settings, false); $form_dark->handleRequest($request); if ($form_dark->isSubmitted() && $form_dark->isValid()) { @@ -200,15 +199,15 @@ class Oomox if ($reset_button->isClicked()) { $current_oomox_settings?->resetTheme(false); } else { - $data = $form_dark->getData(); + $data = $form_dark->getData(); $current_oomox_settings = EntityOomox::create( [ - 'actor_id' => $actor_id, - 'colour_foreground_dark' => $data['colour_foreground_dark'], + 'actor_id' => $actor_id, + 'colour_foreground_dark' => $data['colour_foreground_dark'], 'colour_background_hard_dark' => $data['colour_background_hard_dark'], 'colour_background_card_dark' => $data['colour_background_card_dark'], - 'colour_border_dark' => $data['colour_border_dark'], - 'colour_accent_dark' => $data['colour_accent_dark'], + 'colour_border_dark' => $data['colour_border_dark'], + 'colour_accent_dark' => $data['colour_accent_dark'], ], ); } @@ -225,18 +224,16 @@ class Oomox /** * Renders the resulting CSS file from user options, serves that file as a response * - * @return Response + * @throws ClientException * @throws NoLoggedInUser * @throws ServerException - * - * @throws ClientException */ public function oomoxCSS(): Response { $user = Common::ensureLoggedIn(); $oomox_table = PluginOomox::getEntity($user); - if (is_null($oomox_table)) { + if (\is_null($oomox_table)) { throw new ClientException(_m('No custom colours defined', 404)); } diff --git a/plugins/Oomox/Entity/Oomox.php b/plugins/Oomox/Entity/Oomox.php index 041c7e46ab..86ca7fb8d7 100644 --- a/plugins/Oomox/Entity/Oomox.php +++ b/plugins/Oomox/Entity/Oomox.php @@ -197,20 +197,20 @@ class Oomox extends Entity return $this->modified; } - public function resetTheme(bool $is_light) { + public function resetTheme(bool $is_light) + { if ($is_light) { $this->colour_background_hard_light = '#09090d'; $this->colour_background_card_light = '#ebebeb'; - $this->colour_foreground_light = '#f0f0f0'; - $this->colour_border_light = '#d5d5d5'; - $this->colour_accent_light = '#a22430'; + $this->colour_foreground_light = '#f0f0f0'; + $this->colour_border_light = '#d5d5d5'; + $this->colour_accent_light = '#a22430'; } else { - $this->colour_background_hard_dark = '#141216'; $this->colour_background_card_dark = '#131217'; - $this->colour_foreground_dark = '#f0f6f6'; - $this->colour_border_dark = '#201f25'; - $this->colour_accent_dark = '#5ddbcf'; + $this->colour_foreground_dark = '#f0f6f6'; + $this->colour_border_dark = '#201f25'; + $this->colour_accent_dark = '#5ddbcf'; } } diff --git a/plugins/RepeatNote/RepeatNote.php b/plugins/RepeatNote/RepeatNote.php index 74507de3b5..436581bfb0 100644 --- a/plugins/RepeatNote/RepeatNote.php +++ b/plugins/RepeatNote/RepeatNote.php @@ -29,13 +29,13 @@ use App\Core\Router\RouteLoader; use App\Core\Router\Router; use App\Entity\Activity; use App\Entity\Actor; -use Component\Language\Entity\Language; use App\Entity\Note; use App\Util\Common; use App\Util\Exception\DuplicateFoundException; use App\Util\Exception\NotFoundException; use App\Util\Exception\ServerException; use App\Util\Formatting; +use Component\Language\Entity\Language; use Component\Posting\Posting; use DateTime; use Plugin\RepeatNote\Entity\NoteRepeat; @@ -53,11 +53,11 @@ class RepeatNote extends NoteHandlerPlugin if (!\is_null($repeat_entity)) { return DB::findBy('activity', [ - 'actor_id' => $actor_id, - 'verb' => 'repeat', - 'object_type' => 'note', - 'object_id' => $note->getId() - ], order_by: ['created' => 'DESC'])[0]; + 'actor_id' => $actor_id, + 'verb' => 'repeat', + 'object_type' => 'note', + 'object_id' => $note->getId(), + ], order_by: ['created' => 'DESC'])[0]; } // Create a new note with the same content as the original diff --git a/plugins/TagBasedFiltering/Controller/AddBlocked.php b/plugins/TagBasedFiltering/Controller/AddBlocked.php index f39f272e1d..6926a069dc 100644 --- a/plugins/TagBasedFiltering/Controller/AddBlocked.php +++ b/plugins/TagBasedFiltering/Controller/AddBlocked.php @@ -31,12 +31,12 @@ use function App\Core\I18n\_m; use App\Entity\Actor; use App\Entity\ActorTag; use App\Entity\ActorTagBlock; -use Component\Language\Entity\Language; use App\Entity\Note; use App\Entity\NoteTag; use App\Entity\NoteTagBlock; use App\Util\Common; use App\Util\Exception\RedirectException; +use Component\Language\Entity\Language; use Component\Tag\Tag; use Functional as F; use Plugin\TagBasedFiltering\TagBasedFiltering as TagFilerPlugin; diff --git a/plugins/TreeNotes/TreeNotes.php b/plugins/TreeNotes/TreeNotes.php index c29dd56e72..f1df8787d5 100644 --- a/plugins/TreeNotes/TreeNotes.php +++ b/plugins/TreeNotes/TreeNotes.php @@ -31,7 +31,7 @@ class TreeNotes extends Plugin */ public function onFormatNoteList(array $notes_in, ?array &$notes_out) { - $roots = array_filter($notes_in, static fn (Note $note) => is_null($note->getReplyTo())); + $roots = array_filter($notes_in, static fn (Note $note) => \is_null($note->getReplyTo())); $notes_out = $this->build_tree($roots, $notes_in); } diff --git a/src/Core/Entity.php b/src/Core/Entity.php index a3fb636f38..7ded03a3d7 100644 --- a/src/Core/Entity.php +++ b/src/Core/Entity.php @@ -151,7 +151,7 @@ abstract class Entity public function getNotificationTargetIds(array $ids_already_known = [], ?int $sender_id = null, bool $include_additional = true): array { // Additional actors that should know about this - if (array_key_exists('additional', $ids_already_known)) { + if (\array_key_exists('additional', $ids_already_known)) { return $ids_already_known['additional']; } return []; diff --git a/src/Util/Exception/BugFoundException.php b/src/Util/Exception/BugFoundException.php index 5b4ef08b96..0ced36c6c8 100644 --- a/src/Util/Exception/BugFoundException.php +++ b/src/Util/Exception/BugFoundException.php @@ -44,7 +44,7 @@ class BugFoundException extends ServerException { parent::__construct($message, $code, $previous); $frame = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, limit: 2)[1]; - $file = mb_substr($frame['file'], \mb_strlen(INSTALLDIR) + 1); + $file = mb_substr($frame['file'], mb_strlen(INSTALLDIR) + 1); Log::critical("{$log_message} in {$file}:{$frame['line']}"); } } diff --git a/src/Util/Exception/FileNotAllowedException.php b/src/Util/Exception/FileNotAllowedException.php index 2335de19e0..2b5868a3aa 100644 --- a/src/Util/Exception/FileNotAllowedException.php +++ b/src/Util/Exception/FileNotAllowedException.php @@ -21,7 +21,9 @@ declare(strict_types = 1); namespace App\Util\Exception; -class FileNotAllowedException extends \InvalidArgumentException +use InvalidArgumentException; + +class FileNotAllowedException extends InvalidArgumentException { public function __construct(string $mimetype) { diff --git a/src/Util/Exception/NoSuchActorException.php b/src/Util/Exception/NoSuchActorException.php index fd3e215bfa..43411124be 100644 --- a/src/Util/Exception/NoSuchActorException.php +++ b/src/Util/Exception/NoSuchActorException.php @@ -1,5 +1,7 @@