Skip to content

Commit

Permalink
Declare missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Aug 19, 2024
1 parent 1492a99 commit 1606cbe
Show file tree
Hide file tree
Showing 25 changed files with 58 additions and 54 deletions.
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
->withPhpSets()
->withPreparedSets(
deadCode: true,
typeDeclarations: true,
privatization: true,
earlyReturn: true,
phpunitCodeQuality: true,
Expand Down
4 changes: 2 additions & 2 deletions src/Firebase/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getUser(Stringable|string $uid): UserRecord

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

$users = array_fill_keys($uids, null);

Expand Down Expand Up @@ -490,7 +490,7 @@ public function unlinkProvider($uid, $provider): UserRecord
$provider = array_values(
array_filter(
array_map('strval', (array) $provider),
static fn(string $value) => $value !== '',
static fn(string $value): bool => $value !== '',
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function fromArray(array $settings): self
{
$instance = new self();

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

foreach ($settings as $key => $value) {
switch (mb_strtolower($key)) {
Expand Down Expand Up @@ -116,6 +116,6 @@ public function toArray(): array
'androidMinimumVersion' => $this->androidMinimumVersion,
'androidInstallApp' => $this->androidInstallApp,
'iOSBundleId' => $this->iOSBundleId,
], static fn($value) => is_bool($value) || (is_string($value) && $value !== ''));
], static fn($value): bool => is_bool($value) || (is_string($value) && $value !== ''));
}
}
2 changes: 1 addition & 1 deletion src/Firebase/Auth/UserRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static function mfaInfoFromResponseData(array $data): ?MfaInfo
private static function userInfoFromResponseData(array $data): array
{
return array_map(
static fn(array $userInfoData) => UserInfo::fromResponseData($userInfoData),
static fn(array $userInfoData): UserInfo => UserInfo::fromResponseData($userInfoData),
$data['providerUserInfo'],
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Firebase/Database/Query/Sorter/OrderByChild.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function modifyValue(mixed $value): mixed

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

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

return $value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Firebase/DynamicLink/EventStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ public function appReOpens(): self

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

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

public function filter(callable $filter): self
Expand Down
12 changes: 7 additions & 5 deletions src/Firebase/Http/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
namespace Kreait\Firebase\Http;

use Beste\Json;
use Closure;
use Exception;
use Fig\Http\Message\StatusCodeInterface as StatusCode;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Promise\Create;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\Query;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -29,7 +31,7 @@ final class Middleware
*/
public static function ensureJsonSuffix(): callable
{
return static fn(callable $handler) => static function (RequestInterface $request, ?array $options = null) use ($handler) {
return static fn(callable $handler): Closure => static function (RequestInterface $request, ?array $options = null) use ($handler) {
$uri = $request->getUri();
$path = '/'.ltrim($uri->getPath(), '/');

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

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

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

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

return $response;
},
static function (Exception $reason) use ($logger, $request, $formatter, $errorLogLevel) {
static function (Exception $reason) use ($logger, $request, $formatter, $errorLogLevel): PromiseInterface {
$response = $reason instanceof RequestException ? $reason->getResponse() : null;
$message = $formatter->format($request, $response, $reason);

Expand Down
10 changes: 5 additions & 5 deletions src/Firebase/Messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ public function sendAll($messages, bool $validateOnly = false): MulticastSendRep
$sendReports = array_fill(0, count($messages), null);

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

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

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

$error = $this->exceptionConverter->convertException($reason);
Expand Down Expand Up @@ -159,7 +159,7 @@ public function unsubscribeFromTopic(string|Topic $topic, RegistrationTokens|Reg
public function unsubscribeFromTopics(array $topics, RegistrationTokens|RegistrationToken|array|string $registrationTokenOrTokens): array
{
$topics = array_map(
static fn($topic) => $topic instanceof Topic ? $topic : Topic::fromValue($topic),
static fn($topic): Topic => $topic instanceof Topic ? $topic : Topic::fromValue($topic),
$topics,
);

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

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

return array_keys($this->unsubscribeFromTopics($topics, $token));
})
->otherwise(static fn(Throwable $e) => $e->getMessage())
->otherwise(static fn(Throwable $e): string => $e->getMessage())
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Firebase/Messaging/AndroidConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function withNotificationVisibility(string $notificationVisibility): self

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

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Firebase/Messaging/AppInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function isSubscribedToTopic(Topic|string $topic): bool
$topic = $topic instanceof Topic ? $topic : Topic::fromValue($topic);

return $this->topicSubscriptions
->filter(static fn(TopicSubscription $subscription) => $topic->value() === $subscription->topic()->value())
->filter(static fn(TopicSubscription $subscription): bool => $topic->value() === $subscription->topic()->value())
->count() > 0
;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Firebase/Messaging/AppInstanceApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function subscribeToTopics(array $topics, RegistrationTokens $tokens): ar
'registration_tokens' => $tokenStrings,
],
])
->then(static fn(ResponseInterface $response) => Json::decode((string) $response->getBody(), true))
->then(static fn(ResponseInterface $response): mixed => Json::decode((string) $response->getBody(), true))
;
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public function unsubscribeFromTopics(array $topics, RegistrationTokens $tokens)
'registration_tokens' => $tokenStrings,
],
])
->then(static fn(ResponseInterface $response) => Json::decode((string) $response->getBody(), true))
->then(static fn(ResponseInterface $response): mixed => Json::decode((string) $response->getBody(), true))
;
}

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

return AppInstance::fromRawData($registrationToken, $data);
})
->otherwise(fn(Throwable $e) => Create::rejectionFor($this->errorHandler->convertException($e)))
->otherwise(fn(Throwable $e): PromiseInterface => Create::rejectionFor($this->errorHandler->convertException($e)))
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Firebase/Messaging/CloudMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function jsonSerialize(): array

return array_filter(
$data,
static fn($value) => $value !== null && $value !== [],
static fn($value): bool => $value !== null && $value !== [],
);
}

Expand Down
16 changes: 8 additions & 8 deletions src/Firebase/Messaging/MulticastSendReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function getItems(): array

public function successes(): self
{
return $this->filter(static fn(SendReport $item) => $item->isSuccess());
return $this->filter(static fn(SendReport $item): bool => $item->isSuccess());
}

public function failures(): self
{
return $this->filter(static fn(SendReport $item) => $item->isFailure());
return $this->filter(static fn(SendReport $item): bool => $item->isFailure());
}

public function hasFailures(): bool
Expand Down Expand Up @@ -77,8 +77,8 @@ public function map(callable $callback): array
public function validTokens(): array
{
return $this->successes()
->filter(static fn(SendReport $report) => $report->target()->type() === MessageTarget::TOKEN)
->map(static fn(SendReport $report) => $report->target()->value())
->filter(static fn(SendReport $report): bool => $report->target()->type() === MessageTarget::TOKEN)
->map(static fn(SendReport $report): string => $report->target()->value())
;
}

Expand All @@ -90,8 +90,8 @@ public function validTokens(): array
public function unknownTokens(): array
{
return $this
->filter(static fn(SendReport $report) => $report->messageWasSentToUnknownToken())
->map(static fn(SendReport $report) => $report->target()->value())
->filter(static fn(SendReport $report): bool => $report->messageWasSentToUnknownToken())
->map(static fn(SendReport $report): string => $report->target()->value())
;
}

Expand All @@ -103,8 +103,8 @@ public function unknownTokens(): array
public function invalidTokens(): array
{
return $this
->filter(static fn(SendReport $report) => $report->messageTargetWasInvalid())
->map(static fn(SendReport $report) => $report->target()->value())
->filter(static fn(SendReport $report): bool => $report->messageTargetWasInvalid())
->map(static fn(SendReport $report): string => $report->target()->value())
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Firebase/Messaging/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ public function jsonSerialize(): array
'title' => $this->title,
'body' => $this->body,
'image' => $this->imageUrl,
], static fn($value) => $value !== null);
], static fn($value): bool => $value !== null);
}
}
2 changes: 1 addition & 1 deletion src/Firebase/Messaging/WebPushConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function withUrgency(string $urgency): self
public function jsonSerialize(): array
{
// @phpstan-ignore notIdentical.alwaysTrue
return array_filter($this->config, static fn($value) => $value !== null);
return array_filter($this->config, static fn($value): bool => $value !== null);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Firebase/RemoteConfig/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Kreait\Firebase\Exception\RemoteConfigApiExceptionConverter;
use Kreait\Firebase\Exception\RemoteConfigException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
use Throwable;

use function array_filter;
Expand Down Expand Up @@ -118,12 +117,13 @@ public function rollbackToVersion(VersionNumber $versionNumber): ResponseInterfa
}

/**
* @param string|UriInterface $uri
* @param non-empty-string $method
* @param non-empty-string $uri
* @param array<string, mixed>|null $options
*
* @throws RemoteConfigException
*/
private function requestApi(string $method, $uri, ?array $options = null): ResponseInterface
private function requestApi(string $method, string $uri, ?array $options = null): ResponseInterface
{
$options ??= [];
$options['decode_content'] = 'gzip';
Expand Down
12 changes: 6 additions & 6 deletions src/Firebase/RemoteConfig/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function withCondition(Condition $condition): self
public function conditionNames(): array
{
return array_values(array_unique(
array_map(static fn(Condition $c) => $c->name(), $this->conditions),
array_map(static fn(Condition $c): string => $c->name(), $this->conditions),
));
}

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

return $template;
Expand All @@ -207,9 +207,9 @@ public function withRemovedCondition(string $name): self
*/
public function jsonSerialize(): array
{
$conditions = array_map(fn(Condition $c) => $c->jsonSerialize(), $this->conditions);
$parameters = array_map(fn(Parameter $p) => $p->jsonSerialize(), $this->parameters);
$parameterGroups = array_map(fn(ParameterGroup $p) => $p->jsonSerialize(), $this->parameterGroups);
$conditions = array_map(fn(Condition $c): array => $c->jsonSerialize(), $this->conditions);
$parameters = array_map(fn(Parameter $p): array => $p->jsonSerialize(), $this->parameters);
$parameterGroups = array_map(fn(ParameterGroup $p): array => $p->jsonSerialize(), $this->parameterGroups);

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

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

foreach ($parameter->conditionalValues() as $conditionalValue) {
if (!in_array($conditionalValue->conditionName(), $conditionNames, true)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Firebase/Request/EditUserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function prepareJsonSerialize(): array
'phoneNumber' => $this->phoneNumber,
'photoUrl' => $this->photoUrl,
'password' => $this->clearTextPassword,
], static fn($value) => $value !== null);
], static fn($value): bool => $value !== null);
}

public function hasUid(): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Firebase/Request/UpdateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static function withProperties(array $properties): self
case 'removeproviders':
$request = array_reduce(
(array) $value,
static fn(self $request, $provider) => $request->withRemovedProvider($provider),
static fn(self $request, $provider): \Kreait\Firebase\Request\UpdateUser => $request->withRemovedProvider($provider),
$request,
);

Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Kreait\Firebase\Tests\Integration;

use Closure;
use Kreait\Firebase\Http\HttpClientOptions;
use Kreait\Firebase\Tests\IntegrationTestCase;
use PHPUnit\Framework\Attributes\Test;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function itSupportsAddingAdditionalHttpClientMiddlewares(): void

$check = false;

$middleware = static function (callable $handler) use (&$check) {
$middleware = static function (callable $handler) use (&$check): Closure {
return static function (RequestInterface $request, array $options) use ($handler, &$check) {
$check = true;

Expand Down
Loading

0 comments on commit 1606cbe

Please sign in to comment.