From 9e0a2dd4a0cd5f0d7f5abe1e02f638b1a9559c5a Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 2 Jan 2022 21:44:45 +0000 Subject: [PATCH] [TOOLS] Fix errors found by PHPStan --- components/Posting/Posting.php | 21 ++++++++++----------- plugins/Directory/Controller/Directory.php | 1 + 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php index 0c88bf6bc9..b06b3694b8 100644 --- a/components/Posting/Posting.php +++ b/components/Posting/Posting.php @@ -253,17 +253,16 @@ class Posting extends Component DB::persist($activity); if (!\is_null($target)) { - switch ($target[0]) { - case '!': - $mentions[] = [ - 'mentioned' => [LocalGroup::getActorByNickname(mb_substr($target, 1))], - 'type' => 'group', - 'text' => mb_substr($target, 1), - ]; - break; - default: - throw new ClientException(_m('Unknown target type give in \'In\' field: ' . $target)); - } + $target = \is_int($target) ? Actor::getById($target) : $target; + $mentions[] = [ + 'mentioned' => [$target], + 'type' => match ($target->getType()) { + Actor::PERSON => 'mention', + Actor::GROUP => 'group', + default => throw new ClientException(_m('Unknown target type give in \'In\' field: {target}', ['{target}' => $target?->getNickname() ?? ''])), + }, + 'text' => $target->getNickname(), + ]; } $mention_ids = F\unique(F\flat_map($mentions, fn (array $m) => F\map($m['mentioned'] ?? [], fn (Actor $a) => $a->getId()))); diff --git a/plugins/Directory/Controller/Directory.php b/plugins/Directory/Controller/Directory.php index 33da5ee504..b41f52d70b 100644 --- a/plugins/Directory/Controller/Directory.php +++ b/plugins/Directory/Controller/Directory.php @@ -26,6 +26,7 @@ namespace Plugin\Directory\Controller; use App\Core\DB\DB; use function App\Core\I18n\_m; use App\Entity\Actor; +use App\Util\Common; use App\Util\Exception\BugFoundException; use App\Util\Exception\ClientException; use Component\Collection\Util\Controller\CircleController;