Skip to content

Commit 06db304

Browse files
committed
Fix PHPStan reports after upgrade to PHPStan 2.2
1 parent 51138d7 commit 06db304

10 files changed

Lines changed: 49 additions & 29 deletions

src/Auth/UserMetaData.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
use function array_key_exists;
1111

1212
/**
13+
* @phpstan-import-type UserRecordResponseShape from UserRecord
14+
*
1315
* @phpstan-type UserMetadataResponseShape array{
1416
* createdAt: non-empty-string,
1517
* lastLoginAt?: non-empty-string,
1618
* passwordUpdatedAt?: non-empty-string,
1719
* lastRefreshAt?: non-empty-string
18-
* }
20+
* }|UserRecordResponseShape
1921
*/
2022
final readonly class UserMetaData
2123
{

src/Auth/UserRecord.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,35 +117,38 @@ private static function userMetaDataFromResponseData(array $data): UserMetaData
117117
}
118118

119119
/**
120-
* @param array{
121-
* mfaInfo?: list<MfaInfoResponseShape>
122-
* } $data
120+
* @param UserRecordResponseShape $data
123121
*/
124122
private static function mfaInfoFromResponseData(array $data): ?MfaInfo
125123
{
126-
if (!array_key_exists('mfaInfo', $data)) {
124+
$mfaInfo = $data['mfaInfo'] ?? null;
125+
126+
if ($mfaInfo === null) {
127127
return null;
128128
}
129129

130-
$mfaInfo = array_shift($data['mfaInfo']);
130+
$firstItem = array_shift($mfaInfo);
131131

132-
if ($mfaInfo === null) {
132+
if ($firstItem === null) {
133133
return null;
134134
}
135135

136-
return MfaInfo::fromResponseData($mfaInfo);
136+
return MfaInfo::fromResponseData($firstItem);
137137
}
138138

139139
/**
140-
* @param array{providerUserInfo: list<ProviderUserInfoResponseShape>} $data
140+
* @param UserRecordResponseShape $data
141141
*
142142
* @return list<UserInfo>
143143
*/
144144
private static function userInfoFromResponseData(array $data): array
145145
{
146-
return array_map(
147-
UserInfo::fromResponseData(...),
148-
$data['providerUserInfo'],
149-
);
146+
$userInfo = $data['providerUserInfo'] ?? null;
147+
148+
if (is_array($userInfo)) {
149+
return array_map(UserInfo::fromResponseData(...), $userInfo);
150+
}
151+
152+
return [];
150153
}
151154
}

src/Messaging/ApnsConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function toArray(): array
220220
}
221221

222222
/**
223-
* @return ApnsConfigShape
223+
* @return array<non-empty-string, mixed>
224224
*/
225225
public function jsonSerialize(): array
226226
{

src/Messaging/AppInstance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private function __construct(
3030
* topics?: array<non-empty-string, array{
3131
* addDate?: non-empty-string
3232
* }>
33-
* }
33+
* }, ...
3434
* } $rawData
3535
*/
3636
public static function fromRawData(RegistrationToken $registrationToken, array $rawData): self

src/Messaging/CloudMessage.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
* android?: AndroidConfigShape,
3333
* apns?: ApnsConfig|ApnsConfigShape,
3434
* webpush?: WebPushConfig|WebPushConfigShape,
35-
* fcm_options?: FcmOptions|FcmOptionsShape
35+
* fcm_options?: FcmOptions|FcmOptionsShape,
36+
* ...
3637
* }
3738
*
3839
* @phpstan-type MessageOutputShape array{
@@ -44,7 +45,8 @@
4445
* android?: AndroidConfigShape,
4546
* apns?: ApnsConfigShape,
4647
* webpush?: WebPushConfigShape,
47-
* fcm_options?: FcmOptionsShape
48+
* fcm_options?: FcmOptionsShape,
49+
* ...
4850
* }
4951
*/
5052
final class CloudMessage implements Message

src/Messaging/Notification.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @phpstan-type NotificationShape array{
1313
* title?: string,
1414
* body?: string,
15-
* imageUrl?: string
15+
* image?: string
1616
* }
1717
*/
1818
final class Notification implements JsonSerializable
@@ -30,11 +30,7 @@ public static function create(?string $title = null, ?string $body = null, ?stri
3030
}
3131

3232
/**
33-
* @param array{
34-
* title?: string,
35-
* body?: string,
36-
* image?: string
37-
* } $data
33+
* @param NotificationShape $data
3834
*/
3935
public static function fromArray(array $data): self
4036
{
@@ -84,6 +80,9 @@ public function imageUrl(): ?string
8480
return $this->imageUrl;
8581
}
8682

83+
/**
84+
* @return NotificationShape
85+
*/
8786
public function jsonSerialize(): array
8887
{
8988
return array_filter([

src/Messaging/Processor/SetApnsContentAvailableIfNeeded.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ public function __invoke(Message $message): Message
5151
}
5252

5353
/**
54-
* @param array<string, mixed> $payload
54+
* @param array{
55+
* notification?: null|NotificationShape,
56+
* ...
57+
* } $payload
5558
*/
5659
public function getNotification(array $payload): ?Notification
5760
{
@@ -65,11 +68,14 @@ public function getNotification(array $payload): ?Notification
6568
}
6669

6770
/**
68-
* @param array<string, mixed> $payload
71+
* @param array{
72+
* apns?: null|ApnsConfigShape,
73+
* ...
74+
* } $payload
6975
*/
7076
public function getApnsConfig(array $payload): ApnsConfig
7177
{
72-
$apnsConfig = $payload['apns'] ?? [];
78+
$apnsConfig = $payload['apns'] ?? null;
7379

7480
if (is_array($apnsConfig)) {
7581
return ApnsConfig::fromArray($apnsConfig);

src/Messaging/Processor/SetApnsPushTypeIfNeeded.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ public function __invoke(Message $message): Message
5656
}
5757

5858
/**
59-
* @param array<string, mixed> $payload
59+
* @param array{
60+
* notification?: null|NotificationShape,
61+
* ...
62+
* } $payload
6063
*/
6164
public function getNotification(array $payload): ?Notification
6265
{
@@ -70,11 +73,14 @@ public function getNotification(array $payload): ?Notification
7073
}
7174

7275
/**
73-
* @param array<string, mixed> $payload
76+
* @param array{
77+
* apns?: null|ApnsConfigShape,
78+
* ...
79+
* } $payload
7480
*/
7581
public function getApnsConfig(array $payload): ApnsConfig
7682
{
77-
$apnsConfig = $payload['apns'] ?? [];
83+
$apnsConfig = $payload['apns'] ?? null;
7884

7985
if (is_array($apnsConfig)) {
8086
return ApnsConfig::fromArray($apnsConfig);

src/RemoteConfig.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ private function buildTemplateFromResponse(ResponseInterface $response): Templat
139139
$etag = '*';
140140
}
141141

142+
/** @var RemoteConfigTemplateShape $data */
142143
$data = Json::decode((string) $response->getBody(), true);
143144

144145
return Template::fromArray($data, $etag);

src/Request/UpdateUser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ public function withCustomAttributes(array $customAttributes): self
258258
* customAttributes?: string,
259259
* deleteAttribute?: list<non-empty-string>,
260260
* deleteProvider?: list<non-empty-string>,
261+
* ...<string, mixed>
261262
* }
262263
*/
263264
public function jsonSerialize(): array

0 commit comments

Comments
 (0)