Skip to content

Commit

Permalink
fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed Sep 14, 2023
1 parent 85e9520 commit 9a28ff2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Apn/JwtAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private function newGenerator(): \Iterator
};

$lastToken = $newToken();
while (true) {
while (true) { // @phpstan-ignore-line
$newNow = new \DateTimeImmutable();

if ($newNow > $now->add(new \DateInterval($this->refreshAfter))) {
Expand Down
8 changes: 5 additions & 3 deletions src/Firebase/CloudMessaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public function send(string $projectId, string $token, Notification $notificatio
}

/**
* @param array<mixed, mixed> $data
* @return array<string, mixed>
* @param array<string|int, mixed> $data
* @return array<string|int, string>
*/
private function convertDataToStrings(array $data): array
{
Expand All @@ -112,6 +112,8 @@ private function convertDataToStrings(array $data): array
return \is_array($item) ? \array_map($func, $item) : \call_user_func($callback, $item);
};

return \array_map($func, $data);
/** @var array<string|int, string> $result */
$result = \array_map($func, $data);
return $result;
}
}
6 changes: 3 additions & 3 deletions src/Firebase/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ final class Notification
private $title;

/**
* @var array<mixed, mixed>
* @var array<string|int, mixed>
*/
private $data;

/**
* @param string $body
* @param string $title
* @param array<mixed, mixed> $data
* @param array<string|int, mixed> $data
*/
public function __construct(string $body, string $title, array $data = [])
{
Expand All @@ -49,7 +49,7 @@ public function getTitle(): string
}

/**
* @return array<mixed, mixed>
* @return array<string|int, mixed>
*/
public function getData(): array
{
Expand Down
13 changes: 13 additions & 0 deletions src/Firebase/OauthBearerTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public function __invoke(): string
}

$googleJson = \json_decode($serviceAccount, true);
if (!$googleJson || !\is_array($googleJson)) {
throw new \UnexpectedValueException('Invalid service account file ' . $this->serviceAccountFile . ' passed, cannot decode json.');
}

if (!\array_key_exists('private_key', $googleJson)) {
throw new \UnexpectedValueException('Expecting key `private_key` in service account.');
}

$configuration = Configuration::forSymmetricSigner(
new Sha256(),
InMemory::plainText($googleJson['private_key'])
Expand Down Expand Up @@ -81,6 +89,11 @@ public function __invoke(): string
->getBody();

$authTokens = \json_decode($authResponse, true);

if (!$authTokens || !\is_array($authTokens) || !\array_key_exists('private_key', $authTokens)) {
throw new \UnexpectedValueException('Expecting key `access_token` from Oauth request.');
}

return 'Bearer ' . $authTokens['access_token'];
}
}
2 changes: 1 addition & 1 deletion src/Sender/FirebaseSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function send(Message $message, RecipientInterface $recipient): void
$responseText = (string)$response->getBody();
$responseJson = \json_decode($responseText, true);

if ($responseJson && isset($responseJson['error']['message'])) {
if ($responseJson && \is_array($responseJson) && isset($responseJson['error']['message'])) {
$error = $responseJson['error']['message'];
} else {
$error = $e->getMessage();
Expand Down
6 changes: 3 additions & 3 deletions test/Integration/CloudMessagingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function testDataIsString(): void
$this->callback(
function (Request $request) {
$body = \json_decode((string)$request->getBody(), true);
$this->assertSame("1", $body['message']['data']['true']);
$this->assertSame("", $body['message']['data']['false']);
$this->assertSame("1815", $body['message']['data']['int']);
$this->assertSame("1", $body['message']['data']['true']); // @phpstan-ignore-line
$this->assertSame("", $body['message']['data']['false']); // @phpstan-ignore-line
$this->assertSame("1815", $body['message']['data']['int']); // @phpstan-ignore-line
return true;
}
)
Expand Down

0 comments on commit 9a28ff2

Please sign in to comment.