Skip to content

Commit 006fcbe

Browse files
committed
Declare missing types
1 parent 1492a99 commit 006fcbe

26 files changed

+59
-55
lines changed

rector.php

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
->withPhpSets()
1515
->withPreparedSets(
1616
deadCode: true,
17+
typeDeclarations: true,
1718
privatization: true,
1819
earlyReturn: true,
1920
phpunitCodeQuality: true,

src/Firebase/Auth.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function getUser(Stringable|string $uid): UserRecord
8888

8989
public function getUsers(array $uids): array
9090
{
91-
$uids = array_map(static fn($uid) => Uid::fromString($uid)->value, $uids);
91+
$uids = array_map(static fn($uid): string => Uid::fromString($uid)->value, $uids);
9292

9393
$users = array_fill_keys($uids, null);
9494

@@ -490,7 +490,7 @@ public function unlinkProvider($uid, $provider): UserRecord
490490
$provider = array_values(
491491
array_filter(
492492
array_map('strval', (array) $provider),
493-
static fn(string $value) => $value !== '',
493+
static fn(string $value): bool => $value !== '',
494494
),
495495
);
496496

src/Firebase/Auth/ActionCodeSettings/ValidatedActionCodeSettings.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static function fromArray(array $settings): self
5252
{
5353
$instance = new self();
5454

55-
$settings = array_filter($settings, static fn($value) => $value !== null);
55+
$settings = array_filter($settings, static fn($value): bool => $value !== null);
5656

5757
foreach ($settings as $key => $value) {
5858
switch (mb_strtolower($key)) {
@@ -116,6 +116,6 @@ public function toArray(): array
116116
'androidMinimumVersion' => $this->androidMinimumVersion,
117117
'androidInstallApp' => $this->androidInstallApp,
118118
'iOSBundleId' => $this->iOSBundleId,
119-
], static fn($value) => is_bool($value) || (is_string($value) && $value !== ''));
119+
], static fn($value): bool => is_bool($value) || (is_string($value) && $value !== ''));
120120
}
121121
}

src/Firebase/Auth/UserRecord.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private static function mfaInfoFromResponseData(array $data): ?MfaInfo
144144
private static function userInfoFromResponseData(array $data): array
145145
{
146146
return array_map(
147-
static fn(array $userInfoData) => UserInfo::fromResponseData($userInfoData),
147+
static fn(array $userInfoData): UserInfo => UserInfo::fromResponseData($userInfoData),
148148
$data['providerUserInfo'],
149149
);
150150
}

src/Firebase/Database/Query/Sorter/OrderByChild.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function modifyValue(mixed $value): mixed
3838

3939
$expression = str_replace('/', '.', $this->childKey);
4040

41-
uasort($value, static fn($a, $b) => search($expression, $a) <=> search($expression, $b));
41+
uasort($value, static fn($a, $b): int => search($expression, $a) <=> search($expression, $b));
4242

4343
return $value;
4444
}

src/Firebase/DynamicLink/EventStatistics.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ public function appReOpens(): self
103103

104104
public function filterByType(string $type): self
105105
{
106-
return $this->filter(static fn(array $event) => ($event['event'] ?? null) === $type);
106+
return $this->filter(static fn(array $event): bool => ($event['event'] ?? null) === $type);
107107
}
108108

109109
public function filterByPlatform(string $platform): self
110110
{
111-
return $this->filter(static fn(array $event) => ($event['platform'] ?? null) === $platform);
111+
return $this->filter(static fn(array $event): bool => ($event['platform'] ?? null) === $platform);
112112
}
113113

114114
public function filter(callable $filter): self

src/Firebase/Http/Middleware.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
namespace Kreait\Firebase\Http;
66

77
use Beste\Json;
8+
use Closure;
89
use Exception;
910
use Fig\Http\Message\StatusCodeInterface as StatusCode;
1011
use GuzzleHttp\Exception\RequestException;
1112
use GuzzleHttp\MessageFormatter;
1213
use GuzzleHttp\Promise\Create;
14+
use GuzzleHttp\Promise\PromiseInterface;
1315
use GuzzleHttp\Psr7\Query;
1416
use Psr\Http\Message\RequestInterface;
1517
use Psr\Http\Message\ResponseInterface;
@@ -29,7 +31,7 @@ final class Middleware
2931
*/
3032
public static function ensureJsonSuffix(): callable
3133
{
32-
return static fn(callable $handler) => static function (RequestInterface $request, ?array $options = null) use ($handler) {
34+
return static fn(callable $handler): Closure => static function (RequestInterface $request, ?array $options = null) use ($handler) {
3335
$uri = $request->getUri();
3436
$path = '/'.ltrim($uri->getPath(), '/');
3537

@@ -47,7 +49,7 @@ public static function ensureJsonSuffix(): callable
4749
*/
4850
public static function addDatabaseAuthVariableOverride(?array $override): callable
4951
{
50-
return static fn(callable $handler) => static function (RequestInterface $request, ?array $options = null) use ($handler, $override) {
52+
return static fn(callable $handler): Closure => static function (RequestInterface $request, ?array $options = null) use ($handler, $override) {
5153
$uri = $request->getUri();
5254

5355
$uri = $uri->withQuery(Query::build(
@@ -60,16 +62,16 @@ public static function addDatabaseAuthVariableOverride(?array $override): callab
6062

6163
public static function log(LoggerInterface $logger, MessageFormatter $formatter, string $logLevel, string $errorLogLevel): callable
6264
{
63-
return static fn(callable $handler) => static fn($request, array $options) => $handler($request, $options)->then(
64-
static function (ResponseInterface $response) use ($logger, $request, $formatter, $logLevel, $errorLogLevel) {
65+
return static fn(callable $handler): Closure => static fn($request, array $options) => $handler($request, $options)->then(
66+
static function (ResponseInterface $response) use ($logger, $request, $formatter, $logLevel, $errorLogLevel): ResponseInterface {
6567
$message = $formatter->format($request, $response);
6668
$messageLogLevel = $response->getStatusCode() >= StatusCode::STATUS_BAD_REQUEST ? $errorLogLevel : $logLevel;
6769

6870
$logger->log($messageLogLevel, $message);
6971

7072
return $response;
7173
},
72-
static function (Exception $reason) use ($logger, $request, $formatter, $errorLogLevel) {
74+
static function (Exception $reason) use ($logger, $request, $formatter, $errorLogLevel): PromiseInterface {
7375
$response = $reason instanceof RequestException ? $reason->getResponse() : null;
7476
$message = $formatter->format($request, $response, $reason);
7577

src/Firebase/Messaging.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ public function sendAll($messages, bool $validateOnly = false): MulticastSendRep
8989
$sendReports = array_fill(0, count($messages), null);
9090

9191
$config = [
92-
'fulfilled' => function (ResponseInterface $response, int $index) use ($messages, &$sendReports) {
92+
'fulfilled' => function (ResponseInterface $response, int $index) use ($messages, &$sendReports): void {
9393
$message = $messages[$index];
9494

9595
$json = Json::decode((string) $response->getBody(), true);
9696

9797
$sendReports[$index] = SendReport::success($message->target(), $json, $message);
9898
},
99-
'rejected' => function (Throwable $reason, int $index) use ($messages, &$sendReports) {
99+
'rejected' => function (Throwable $reason, int $index) use ($messages, &$sendReports): void {
100100
$message = $messages[$index];
101101

102102
$error = $this->exceptionConverter->convertException($reason);
@@ -159,7 +159,7 @@ public function unsubscribeFromTopic(string|Topic $topic, RegistrationTokens|Reg
159159
public function unsubscribeFromTopics(array $topics, RegistrationTokens|RegistrationToken|array|string $registrationTokenOrTokens): array
160160
{
161161
$topics = array_map(
162-
static fn($topic) => $topic instanceof Topic ? $topic : Topic::fromValue($topic),
162+
static fn($topic): Topic => $topic instanceof Topic ? $topic : Topic::fromValue($topic),
163163
$topics,
164164
);
165165

@@ -177,7 +177,7 @@ public function unsubscribeFromAllTopics($registrationTokenOrTokens): array
177177
foreach ($tokens as $token) {
178178
$promises[$token->value()] = $this->appInstanceApi
179179
->getAppInstanceAsync($token)
180-
->then(function (AppInstance $appInstance) use ($token) {
180+
->then(function (AppInstance $appInstance) use ($token): array {
181181
$topics = [];
182182

183183
foreach ($appInstance->topicSubscriptions() as $subscription) {
@@ -186,7 +186,7 @@ public function unsubscribeFromAllTopics($registrationTokenOrTokens): array
186186

187187
return array_keys($this->unsubscribeFromTopics($topics, $token));
188188
})
189-
->otherwise(static fn(Throwable $e) => $e->getMessage())
189+
->otherwise(static fn(Throwable $e): string => $e->getMessage())
190190
;
191191
}
192192

src/Firebase/Messaging/AndroidConfig.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public function withNotificationVisibility(string $notificationVisibility): self
234234

235235
public function jsonSerialize(): array
236236
{
237-
return array_filter($this->config, static fn($value) => $value !== null && $value !== []);
237+
return array_filter($this->config, static fn($value): bool => $value !== null && $value !== []);
238238
}
239239

240240
/**

src/Firebase/Messaging/AppInstance.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function isSubscribedToTopic(Topic|string $topic): bool
6464
$topic = $topic instanceof Topic ? $topic : Topic::fromValue($topic);
6565

6666
return $this->topicSubscriptions
67-
->filter(static fn(TopicSubscription $subscription) => $topic->value() === $subscription->topic()->value())
67+
->filter(static fn(TopicSubscription $subscription): bool => $topic->value() === $subscription->topic()->value())
6868
->count() > 0
6969
;
7070
}

src/Firebase/Messaging/AppInstanceApiClient.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function subscribeToTopics(array $topics, RegistrationTokens $tokens): ar
4747
'registration_tokens' => $tokenStrings,
4848
],
4949
])
50-
->then(static fn(ResponseInterface $response) => Json::decode((string) $response->getBody(), true))
50+
->then(static fn(ResponseInterface $response): mixed => Json::decode((string) $response->getBody(), true))
5151
;
5252
}
5353

@@ -114,7 +114,7 @@ public function unsubscribeFromTopics(array $topics, RegistrationTokens $tokens)
114114
'registration_tokens' => $tokenStrings,
115115
],
116116
])
117-
->then(static fn(ResponseInterface $response) => Json::decode((string) $response->getBody(), true))
117+
->then(static fn(ResponseInterface $response): mixed => Json::decode((string) $response->getBody(), true))
118118
;
119119
}
120120

@@ -165,12 +165,12 @@ public function getAppInstanceAsync(RegistrationToken $registrationToken): Promi
165165
{
166166
return $this->client
167167
->requestAsync('GET', '/iid/'.$registrationToken->value().'?details=true')
168-
->then(static function (ResponseInterface $response) use ($registrationToken) {
168+
->then(static function (ResponseInterface $response) use ($registrationToken): AppInstance {
169169
$data = Json::decode((string) $response->getBody(), true);
170170

171171
return AppInstance::fromRawData($registrationToken, $data);
172172
})
173-
->otherwise(fn(Throwable $e) => Create::rejectionFor($this->errorHandler->convertException($e)))
173+
->otherwise(fn(Throwable $e): PromiseInterface => Create::rejectionFor($this->errorHandler->convertException($e)))
174174
;
175175
}
176176

src/Firebase/Messaging/CloudMessage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public function jsonSerialize(): array
250250

251251
return array_filter(
252252
$data,
253-
static fn($value) => $value !== null && $value !== [],
253+
static fn($value): bool => $value !== null && $value !== [],
254254
);
255255
}
256256

src/Firebase/Messaging/MulticastSendReport.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public function getItems(): array
4343

4444
public function successes(): self
4545
{
46-
return $this->filter(static fn(SendReport $item) => $item->isSuccess());
46+
return $this->filter(static fn(SendReport $item): bool => $item->isSuccess());
4747
}
4848

4949
public function failures(): self
5050
{
51-
return $this->filter(static fn(SendReport $item) => $item->isFailure());
51+
return $this->filter(static fn(SendReport $item): bool => $item->isFailure());
5252
}
5353

5454
public function hasFailures(): bool
@@ -77,8 +77,8 @@ public function map(callable $callback): array
7777
public function validTokens(): array
7878
{
7979
return $this->successes()
80-
->filter(static fn(SendReport $report) => $report->target()->type() === MessageTarget::TOKEN)
81-
->map(static fn(SendReport $report) => $report->target()->value())
80+
->filter(static fn(SendReport $report): bool => $report->target()->type() === MessageTarget::TOKEN)
81+
->map(static fn(SendReport $report): string => $report->target()->value())
8282
;
8383
}
8484

@@ -90,8 +90,8 @@ public function validTokens(): array
9090
public function unknownTokens(): array
9191
{
9292
return $this
93-
->filter(static fn(SendReport $report) => $report->messageWasSentToUnknownToken())
94-
->map(static fn(SendReport $report) => $report->target()->value())
93+
->filter(static fn(SendReport $report): bool => $report->messageWasSentToUnknownToken())
94+
->map(static fn(SendReport $report): string => $report->target()->value())
9595
;
9696
}
9797

@@ -103,8 +103,8 @@ public function unknownTokens(): array
103103
public function invalidTokens(): array
104104
{
105105
return $this
106-
->filter(static fn(SendReport $report) => $report->messageTargetWasInvalid())
107-
->map(static fn(SendReport $report) => $report->target()->value())
106+
->filter(static fn(SendReport $report): bool => $report->messageTargetWasInvalid())
107+
->map(static fn(SendReport $report): string => $report->target()->value())
108108
;
109109
}
110110

src/Firebase/Messaging/Notification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ public function jsonSerialize(): array
9999
'title' => $this->title,
100100
'body' => $this->body,
101101
'image' => $this->imageUrl,
102-
], static fn($value) => $value !== null);
102+
], static fn($value): bool => $value !== null);
103103
}
104104
}

src/Firebase/Messaging/WebPushConfig.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function withUrgency(string $urgency): self
146146
public function jsonSerialize(): array
147147
{
148148
// @phpstan-ignore notIdentical.alwaysTrue
149-
return array_filter($this->config, static fn($value) => $value !== null);
149+
return array_filter($this->config, static fn($value): bool => $value !== null);
150150
}
151151

152152
/**

src/Firebase/RemoteConfig/ApiClient.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Kreait\Firebase\Exception\RemoteConfigApiExceptionConverter;
1010
use Kreait\Firebase\Exception\RemoteConfigException;
1111
use Psr\Http\Message\ResponseInterface;
12-
use Psr\Http\Message\UriInterface;
1312
use Throwable;
1413

1514
use function array_filter;
@@ -118,12 +117,13 @@ public function rollbackToVersion(VersionNumber $versionNumber): ResponseInterfa
118117
}
119118

120119
/**
121-
* @param string|UriInterface $uri
120+
* @param non-empty-string $method
121+
* @param non-empty-string $uri
122122
* @param array<string, mixed>|null $options
123123
*
124124
* @throws RemoteConfigException
125125
*/
126-
private function requestApi(string $method, $uri, ?array $options = null): ResponseInterface
126+
private function requestApi(string $method, string $uri, ?array $options = null): ResponseInterface
127127
{
128128
$options ??= [];
129129
$options['decode_content'] = 'gzip';

src/Firebase/RemoteConfig/ConditionalValue.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function basedOn($condition): self
4444
/**
4545
* @return RemoteConfigParameterValueShape|non-empty-string
4646
*/
47-
public function value()
47+
public function value(): string|array
4848
{
4949
$data = $this->value->toArray();
5050

src/Firebase/RemoteConfig/Template.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function withCondition(Condition $condition): self
181181
public function conditionNames(): array
182182
{
183183
return array_values(array_unique(
184-
array_map(static fn(Condition $c) => $c->name(), $this->conditions),
184+
array_map(static fn(Condition $c): string => $c->name(), $this->conditions),
185185
));
186186
}
187187

@@ -192,7 +192,7 @@ public function withRemovedCondition(string $name): self
192192
{
193193
$template = clone $this;
194194
$template->conditions = array_values(
195-
array_filter($this->conditions, static fn(Condition $c) => $c->name() !== $name),
195+
array_filter($this->conditions, static fn(Condition $c): bool => $c->name() !== $name),
196196
);
197197

198198
return $template;
@@ -207,9 +207,9 @@ public function withRemovedCondition(string $name): self
207207
*/
208208
public function jsonSerialize(): array
209209
{
210-
$conditions = array_map(fn(Condition $c) => $c->jsonSerialize(), $this->conditions);
211-
$parameters = array_map(fn(Parameter $p) => $p->jsonSerialize(), $this->parameters);
212-
$parameterGroups = array_map(fn(ParameterGroup $p) => $p->jsonSerialize(), $this->parameterGroups);
210+
$conditions = array_map(fn(Condition $c): array => $c->jsonSerialize(), $this->conditions);
211+
$parameters = array_map(fn(Parameter $p): array => $p->jsonSerialize(), $this->parameters);
212+
$parameterGroups = array_map(fn(ParameterGroup $p): array => $p->jsonSerialize(), $this->parameterGroups);
213213

214214
return [
215215
'conditions' => $conditions !== [] ? $conditions : null,
@@ -273,7 +273,7 @@ private static function buildParameterGroup(string $name, array $parameterGroupD
273273

274274
private function assertThatAllConditionalValuesAreValid(Parameter $parameter): void
275275
{
276-
$conditionNames = array_map(static fn(Condition $c) => $c->name(), $this->conditions);
276+
$conditionNames = array_map(static fn(Condition $c): string => $c->name(), $this->conditions);
277277

278278
foreach ($parameter->conditionalValues() as $conditionalValue) {
279279
if (!in_array($conditionalValue->conditionName(), $conditionNames, true)) {

src/Firebase/Request/EditUserTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function prepareJsonSerialize(): array
160160
'phoneNumber' => $this->phoneNumber,
161161
'photoUrl' => $this->photoUrl,
162162
'password' => $this->clearTextPassword,
163-
], static fn($value) => $value !== null);
163+
], static fn($value): bool => $value !== null);
164164
}
165165

166166
public function hasUid(): bool

src/Firebase/Request/UpdateUser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public static function withProperties(array $properties): self
145145
case 'removeproviders':
146146
$request = array_reduce(
147147
(array) $value,
148-
static fn(self $request, $provider) => $request->withRemovedProvider($provider),
148+
static fn(self $request, $provider): \Kreait\Firebase\Request\UpdateUser => $request->withRemovedProvider($provider),
149149
$request,
150150
);
151151

0 commit comments

Comments
 (0)