Skip to content

Commit d160c16

Browse files
Merge pull request #2820 from nextcloud/bugfix/noid/fix-psalm-types-in-webpush
fix(webpush): Fix psalm types in WebPush code
2 parents f74dbfe + 830e4fe commit d160c16

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

lib/Push.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Push {
6666
*/
6767
protected array $userStatuses = [];
6868
/**
69-
* @psalm-var array<string, list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>>
69+
* @psalm-var array<string, list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}>>
7070
*/
7171
protected array $userWebPushDevices = [];
7272
/**
@@ -175,23 +175,20 @@ public function flushPayloads(): void {
175175
}
176176

177177
/**
178-
* @param array $devices
179-
* @psalm-param $devices list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>
180-
* @param string $app
181-
* @return array
182-
* @psalm-return list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>
178+
* @psalm-param list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}> $devices
179+
* @psalm-return list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}>
183180
*/
184181
public function filterWebPushDeviceList(array $devices, string $app): array {
185182
// Consider all 3 options as 'talk'
186183
if (\in_array($app, ['spreed', 'talk', 'admin_notification_talk'], true)) {
187184
$app = 'talk';
188185
}
189186

190-
return array_filter($devices, function ($device) use ($app) {
187+
return array_values(array_filter($devices, function ($device) use ($app) {
191188
$appTypes = explode(',', $device['app_types']);
192189
return $device['activated'] && (\in_array($app, $appTypes)
193190
|| (\in_array('all', $appTypes) && !\in_array('-' . $app, $appTypes)));
194-
});
191+
}));
195192
}
196193

197194

@@ -299,6 +296,9 @@ public function pushToDevice(int $id, INotification $notification, ?OutputInterf
299296
$this->proxyPushToDevice($id, $user, $proxyDevices, $notification, $output);
300297
}
301298

299+
/**
300+
* @param list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}> $devices
301+
*/
302302
public function webPushToDevice(int $id, IUser $user, array $devices, INotification $notification, ?OutputInterface $output = null): void {
303303
if (empty($devices)) {
304304
$this->printInfo('<comment>No web push devices found for user</comment>');
@@ -1042,7 +1042,7 @@ protected function getProxyDevicesForUsers(array $userIds): array {
10421042

10431043
/**
10441044
* @param string $uid
1045-
* @return list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>
1045+
* @return list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}>
10461046
*/
10471047
protected function getWebPushDevicesForUser(string $uid): array {
10481048
$query = $this->db->getQueryBuilder();
@@ -1051,6 +1051,7 @@ protected function getWebPushDevicesForUser(string $uid): array {
10511051
->where($query->expr()->eq('uid', $query->createNamedParameter($uid)));
10521052

10531053
$result = $query->executeQuery();
1054+
/** @var list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}> $devices */
10541055
$devices = $result->fetchAll();
10551056
$result->closeCursor();
10561057

@@ -1059,7 +1060,7 @@ protected function getWebPushDevicesForUser(string $uid): array {
10591060

10601061
/**
10611062
* @param string[] $userIds
1062-
* @return array<string, list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>>
1063+
* @return array<string, list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}>>
10631064
*/
10641065
protected function getWebPushDevicesForUsers(array $userIds): array {
10651066
$query = $this->db->getQueryBuilder();
@@ -1070,6 +1071,7 @@ protected function getWebPushDevicesForUsers(array $userIds): array {
10701071
$devices = [];
10711072
$result = $query->executeQuery();
10721073
while ($row = $result->fetch()) {
1074+
/** @psalm-var array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string} $row */
10731075
if (!isset($devices[$row['uid']])) {
10741076
$devices[$row['uid']] = [];
10751077
}

lib/WebPushClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function notify(string $endpoint, string $uaPublicKey, string $auth, stri
118118
// the callback could be defined by the caller
119119
// For the moment, it is used during registration only - no need to catch 404 &co
120120
// as the registration isn't activated
121-
$callback = function ($r) {
121+
$callback = function ($r): void {
122122
};
123123
$c->flushPooled($callback);
124124
}

tests/psalm-baseline.xml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="6.15.0@204d06619833a297b402cbc66be7f2df74437db4">
2+
<files psalm-version="6.15.1@28dc127af1b5aecd52314f6f645bafc10d0e11f9">
33
<file src="lib/Controller/PushController.php">
44
<UndefinedClass>
55
<code><![CDATA[$this->identityProof]]></code>
@@ -21,26 +21,16 @@
2121
</file>
2222
<file src="lib/Push.php">
2323
<LessSpecificReturnStatement>
24-
<code><![CDATA[$devices]]></code>
25-
<code><![CDATA[$devices]]></code>
2624
<code><![CDATA[$devices]]></code>
2725
<code><![CDATA[$devices]]></code>
2826
<code><![CDATA[$otherDevices]]></code>
2927
<code><![CDATA[$otherDevices]]></code>
3028
<code><![CDATA[$talkDevices]]></code>
31-
<code><![CDATA[array_filter($devices, function ($device) use ($app) {
32-
$appTypes = explode(',', $device['app_types']);
33-
return $device['activated'] && (\in_array($app, $appTypes)
34-
|| (\in_array('all', $appTypes) && !\in_array('-' . $app, $appTypes)));
35-
})]]></code>
3629
</LessSpecificReturnStatement>
3730
<MoreSpecificReturnType>
3831
<code><![CDATA[array<string, list<array{id: int, uid: string, token: int, deviceidentifier: string, devicepublickey: string, devicepublickeyhash: string, pushtokenhash: string, proxyserver: string, apptype: string}>>]]></code>
39-
<code><![CDATA[array<string, list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>>]]></code>
4032
<code><![CDATA[list<array{id: int, uid: string, token: int, deviceidentifier: string, devicepublickey: string, devicepublickeyhash: string, pushtokenhash: string, proxyserver: string, apptype: string}>]]></code>
4133
<code><![CDATA[list<array{id: int, uid: string, token: int, deviceidentifier: string, devicepublickey: string, devicepublickeyhash: string, pushtokenhash: string, proxyserver: string, apptype: string}>]]></code>
42-
<code><![CDATA[list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>]]></code>
43-
<code><![CDATA[list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>]]></code>
4434
</MoreSpecificReturnType>
4535
<UndefinedClass>
4636
<code><![CDATA[$e]]></code>

0 commit comments

Comments
 (0)