Skip to content

Commit 25e4df6

Browse files
committed
fix: phpstan (with some cheating - wip)
1 parent 8f2111a commit 25e4df6

26 files changed

+92
-67
lines changed

extensions/realtime/src/Push/Discussion/NewActivity.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class NewActivity extends Subscriber
2222
{
23-
public function subscribe(Dispatcher $events)
23+
public function subscribe(Dispatcher $events): void
2424
{
2525
// Created and Posted both are lined up for dispatching
2626
// after saving by Discussion::create and CommentPost::reply
@@ -29,7 +29,10 @@ public function subscribe(Dispatcher $events)
2929
$this->listen(Posted::class, [$this, 'replied']);
3030

3131
// Best answer setting or unsetting its best answer.
32-
$this->listen([BestAnswer\BestAnswerSet::class, BestAnswer\BestAnswerUnset::class], [$this, 'bestAnswer']);
32+
if (class_exists(BestAnswer\BestAnswerSet::class) && class_exists(BestAnswer\BestAnswerUnset::class)) {
33+
/** @phpstan-ignore-next-line */
34+
$this->listen([BestAnswer\BestAnswerSet::class, BestAnswer\BestAnswerUnset::class], [$this, 'bestAnswer']);
35+
}
3336

3437
// Locking or unlocking a discussion via `flarum/lock`.
3538
$this->listen([Lock\DiscussionWasLocked::class, Lock\DiscussionWasUnlocked::class], [$this, 'locked']);
@@ -50,7 +53,7 @@ public function started(Started $event)
5053
));
5154
}
5255

53-
public function replied(Posted $event)
56+
public function replied(Posted $event): void
5457
{
5558
// Prevent sending for the OP, because the Created event
5659
// was also fired.
@@ -65,7 +68,7 @@ public function replied(Posted $event)
6568
));
6669
}
6770

68-
public function bestAnswer($event)
71+
public function bestAnswer(object $event): void
6972
{
7073
$this->queue()->push(new SendTriggerJob(
7174
'bestAnswerMutation',
@@ -87,7 +90,7 @@ public function locked($event)
8790
));
8891
}
8992

90-
public function renamed(Renamed $event)
93+
public function renamed(Renamed $event): void
9194
{
9295
$this->queue()->push(new SendTriggerJob(
9396
'discussionRenamed',

extensions/realtime/src/Push/Jobs/SendDialogMessageJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727
parent::__construct();
2828
}
2929

30-
public function __invoke(Queue $queue)
30+
public function __invoke(Queue $queue): void
3131
{
3232
/** @var DialogMessage $message */
3333
$message = $this->model;
@@ -72,7 +72,7 @@ private function getConnectedDialogUsers(Dialog $dialog): Collection
7272
})->values();
7373
}
7474

75-
public function middleware()
75+
public function middleware(): array
7676
{
7777
$key = sprintf(
7878
'%s:%s.%s',

extensions/realtime/src/Push/Jobs/SendFlaggedJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(private Discussion $discussion)
1919
parent::__construct();
2020
}
2121

22-
public function handle(Queue $queue)
22+
public function handle(Queue $queue): void
2323
{
2424
$users = $this->connectedUsers($this->discussion);
2525

extensions/realtime/src/Push/Jobs/SendGeneratedPayloadJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(private string $event, private AbstractModel $model,
2222
parent::__construct();
2323
}
2424

25-
public function handle(Generator $generator, Pusher $pusher)
25+
public function handle(Generator $generator, Pusher $pusher): void
2626
{
2727
$channel = $this->recipient
2828
? "private-user={$this->recipient->id}"
@@ -42,7 +42,7 @@ public function handle(Generator $generator, Pusher $pusher)
4242
);
4343
}
4444

45-
public function middleware()
45+
public function middleware(): array
4646
{
4747
$key = sprintf(
4848
'%s:%s:%s-%s:%s',

extensions/realtime/src/Push/Jobs/SendNotificationsJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(private BlueprintInterface $blueprint, private array
2121
parent::__construct();
2222
}
2323

24-
public function handle(Queue $queue)
24+
public function handle(Queue $queue): void
2525
{
2626
// Only dispatch notification jobs for users on the socket.
2727
$intersect = $this->connectedUsers()->intersect($this->recipients);

extensions/realtime/src/Push/Jobs/SendTriggerJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
parent::__construct();
2626
}
2727

28-
public function __invoke(Queue $queue)
28+
public function __invoke(Queue $queue): void
2929
{
3030
// Resolve a discussion for use with `visibleTo` permission checks.
3131
if ($this->model instanceof Discussion) {
@@ -58,7 +58,7 @@ public function __invoke(Queue $queue)
5858
}
5959
}
6060

61-
public function middleware()
61+
public function middleware(): array
6262
{
6363
$key = sprintf(
6464
'%s:%s.%s',

extensions/realtime/src/Push/Post/NewActivity.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,33 @@
2424

2525
class NewActivity extends Subscriber
2626
{
27-
public function subscribe(Dispatcher $events)
27+
public function subscribe(Dispatcher $events): void
2828
{
2929
$this->listen(Flagged::class, [$this, 'flagged']);
3030
$this->listen(FlagDismissed::class, [$this, 'flagged']);
3131

3232
$this->listen(PostWasLiked::class, [$this, 'likes']);
3333
$this->listen(PostWasUnliked::class, [$this, 'likes']);
3434

35-
$this->listen(PostWasVoted::class, [$this, 'voted']);
35+
if (class_exists(PostWasVoted::class)) {
36+
/** @phpstan-ignore-next-line */
37+
$this->listen(PostWasVoted::class, [$this, 'voted']);
38+
}
3639

37-
$this->listen(PostWasReacted::class, [$this, 'reactions']);
38-
$this->listen(PostWasUnreacted::class, [$this, 'reactions']);
40+
if (class_exists(PostWasReacted::class) && class_exists(PostWasUnreacted::class)) {
41+
/** @phpstan-ignore-next-line */
42+
$this->listen(PostWasReacted::class, [$this, 'reactions']);
43+
/** @phpstan-ignore-next-line */
44+
$this->listen(PostWasUnreacted::class, [$this, 'reactions']);
45+
}
3946

4047
$this->listen(Revised::class, [$this, 'revised']);
4148
}
4249

4350
/**
4451
* @param Flagged|FlagDismissed $event
4552
*/
46-
public function flagged($event)
53+
public function flagged(object $event): void
4754
{
4855
$discussion = $event->flag->post->discussion;
4956

@@ -60,7 +67,7 @@ public function flagged($event)
6067
/**
6168
* @param PostWasUnliked|PostWasLiked $event
6269
*/
63-
public function likes($event)
70+
public function likes(object $event): void
6471
{
6572
$this->queue()->push(new SendTriggerJob(
6673
'likesMutation',
@@ -72,28 +79,38 @@ public function likes($event)
7279
/**
7380
* @param PostWasVoted $event
7481
* @return void
82+
* @phpstan-ignore-next-line
7583
*/
76-
public function voted(PostWasVoted $event)
84+
public function voted(object $event): void
7785
{
86+
/** @phpstan-ignore-next-line */
87+
$post = $event->vote->post;
88+
7889
$this->queue()->push(new SendTriggerJob(
7990
'votedMutation',
80-
$event->vote->post
91+
$post
8192
));
8293
}
8394

8495
/**
8596
* @param PostWasReacted|PostWasUnreacted $event
97+
* @phpstan-ignore-next-line
8698
*/
87-
public function reactions($event)
99+
public function reactions(object $event): void
88100
{
101+
/** @phpstan-ignore-next-line */
102+
$post = $event->post;
103+
/** @phpstan-ignore-next-line */
104+
$user = $event->user;
105+
89106
$this->queue()->push(new SendTriggerJob(
90107
'reactionsMutation',
91-
$event->post,
92-
$event->user
108+
$post,
109+
$user
93110
));
94111
}
95112

96-
public function revised(Revised $event)
113+
public function revised(Revised $event): void
97114
{
98115
$this->queue()->push(new SendTriggerJob(
99116
'revisedEvent',

extensions/realtime/src/Websocket/Channel/Channel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function hasConnection(ConnectionInterface $connection): bool
6262
return isset($this->connections[$connection->socketId]);
6363
}
6464

65-
public function saveConnection(ConnectionInterface $connection)
65+
public function saveConnection(ConnectionInterface $connection): void
6666
{
6767
/** @phpstan-ignore-next-line */
6868
$this->connections[$connection->socketId] = $connection;
@@ -94,7 +94,7 @@ public function broadcastToEveryoneExcept(stdClass $payload, ?string $socketId):
9494
return true;
9595
}
9696

97-
protected function verifySignature(ConnectionInterface $connection, stdClass $payload)
97+
protected function verifySignature(ConnectionInterface $connection, stdClass $payload): void
9898
{
9999
/** @phpstan-ignore-next-line */
100100
$signature = "{$connection->socketId}:{$this->getName()}";

extensions/realtime/src/Websocket/Channel/Manager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public function getChannelMembers(string $channel): PromiseInterface
198198
{
199199
$members = $this->users[$channel] ?? [];
200200

201+
/** @phpstan-ignore-next-line */
201202
$members = collect($members)->map(function ($user) {
202203
return json_decode($user);
203204
})->unique('user_id')->toArray();
@@ -219,7 +220,7 @@ public function getChannelsMembersCount(array $channelNames): PromiseInterface
219220
return $this->createFulfilledPromise($results);
220221
}
221222

222-
public function getMemberSockets($userId, string $channel): PromiseInterface
223+
public function getMemberSockets(int|string $userId, string $channel): PromiseInterface
223224
{
224225
return $this->createFulfilledPromise($this->userSockets["$channel:$userId"] ?? []);
225226
}

extensions/realtime/src/Websocket/Channel/PresenceChannel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function subscribe(ConnectionInterface $connection, stdClass $payload): b
3838
'channel' => $this->getName(),
3939
'data' => json_encode([
4040
'presence' => [
41+
/** @phpstan-ignore-next-line */
4142
'ids' => collect($users)->map(function ($user) {
4243
return (string) $user->user_id;
4344
})->values(),

0 commit comments

Comments
 (0)