[TOOLS] Fix errors pointed out by PHPStan level 4

This commit is contained in:
2022-10-19 22:38:49 +01:00
parent 4d7742e0e1
commit edeee49af9
37 changed files with 168 additions and 198 deletions

View File

@@ -40,6 +40,10 @@ use Plugin\WebHooks\Controller as C;
use Plugin\WebHooks\Entity as E;
use Symfony\Component\HttpFoundation\Request;
/**
* @phpstan-type AliasNotifications array{ sender: Actor, activity: Activity, effective_targets: array<Actor>, reason: ?string }
* @phpstan-type AliasSubscriptions array{ subscriber: Actor, activity: Activity, target: Actor, reason: ?string }
*/
class WebHooks extends Plugin
{
public const controller_route = 'webhook';
@@ -86,33 +90,33 @@ class WebHooks extends Plugin
}
/**
* @param array<Actor $sender, Activity $activity, array $effective_targets, ?string $reason> $args
* @param AliasNotifications|AliasSubscriptions $args
*/
public function onQueueWebhook(string $type, string $hook_target, Actor $actor, array $args): EventResult
{
switch ($type) {
case 'notifications':
[$sender, $activity, $targets, $reason] = $args;
$data = [
'type' => 'notification',
'activity' => '%activity%',
'actor' => ['id' => $sender->getId(), 'nickname' => $sender->getNickname()],
'targets' => F\map(array_values($targets), fn (Actor $actor) => ['id' => $actor->getId(), 'nickname' => $actor->getNickname()]),
'reason' => $reason,
];
break;
case 'subscriptions':
[$subscriber, $activity, $target, $reason] = $args;
$data = [
'type' => 'subscription',
'activity' => '%activity%',
'actor' => ['id' => $subscriber->getId(), 'nickname' => $subscriber->getNickname()],
'targets' => [['id' => $target->getId(), 'nickname' => $target->getNickname()]],
'reason' => $reason,
];
break;
default:
throw new ServerException("Webhook notification handler for event {$type} not implemented");
case 'notifications':
['sender' => $sender, 'activity' => $activity, 'effective_targets' => $targets, 'reason' => $reason] = $args;
$data = [
'type' => 'notification',
'activity' => '%activity%',
'actor' => ['id' => $sender->getId(), 'nickname' => $sender->getNickname()],
'targets' => F\map(array_values($targets), fn (Actor $actor) => ['id' => $actor->getId(), 'nickname' => $actor->getNickname()]),
'reason' => $reason,
];
break;
case 'subscriptions':
['subscriber' => $subscriber, 'activity' => $activity, 'target' => $target, 'reason' => $reason] = $args;
$data = [
'type' => 'subscription',
'activity' => '%activity%',
'actor' => ['id' => $subscriber->getId(), 'nickname' => $subscriber->getNickname()],
'targets' => [['id' => $target->getId(), 'nickname' => $target->getNickname()]],
'reason' => $reason,
];
break;
default:
throw new ServerException("Webhook notification handler for event {$type} not implemented");
}
// toJson(Activity) is already JSON (hopefully that's obvious :') ), so replace it after converting the rest to JSON