Skip to content

Commit 5510aff

Browse files
committed
Drop exception code when wrapping exceptions
`Throwable::getCode()` can be non-int.
1 parent abbab22 commit 5510aff

26 files changed

Lines changed: 80 additions & 42 deletions

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ parameters:
2323

2424
checkUninitializedProperties: true
2525

26+
checkBenevolentUnionTypes: true
2627
checkTooWideReturnTypesInProtectedAndPublicMethods: true
2728
reportAlwaysTrueInLastCondition: true
2829
reportPossiblyNonexistentConstantArrayOffset: true

src/Firebase/AppCheck/AppCheckTokenVerifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ private function decodeJwt(string $token): DecodedAppCheckToken
6161
/** @var DecodedAppCheckTokenShape $payload */
6262
$payload = (array) JWT::decode($token, $this->keySet);
6363
} catch (LogicException $e) {
64-
throw new InvalidAppCheckToken($e->getMessage(), $e->getCode(), $e);
64+
throw new InvalidAppCheckToken(message: $e->getMessage(), previous: $e);
6565
} catch (Throwable $e) {
66-
throw new FailedToVerifyAppCheckToken($e->getMessage(), $e->getCode(), $e);
66+
throw new FailedToVerifyAppCheckToken(message: $e->getMessage(), previous: $e);
6767
}
6868

6969
return DecodedAppCheckToken::fromArray($payload);

src/Firebase/Auth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ public function sendEmailActionLink(string $type, Stringable|string $email, $act
312312
try {
313313
$user = $this->getUserByEmail($email);
314314
} catch (Throwable $e) {
315-
throw new FailedToSendActionLink($e->getMessage(), $e->getCode(), $e);
315+
throw new FailedToSendActionLink(message: $e->getMessage(), previous: $e);
316316
}
317317

318318
try {
319319
$signInResult = $this->signInAsUser($user);
320320
} catch (Throwable $e) {
321-
throw new FailedToSendActionLink($e->getMessage(), $e->getCode(), $e);
321+
throw new FailedToSendActionLink(message: $e->getMessage(), previous: $e);
322322
}
323323

324324
$idToken = $signInResult->idToken();

src/Firebase/Auth/CreateActionLink/GuzzleApiClientHandler.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public function handle(CreateActionLink $action): string
4040
try {
4141
$response = $this->client->send($request, ['http_errors' => false]);
4242
} catch (ClientExceptionInterface $e) {
43-
throw new FailedToCreateActionLink('Failed to create action link: '.$e->getMessage(), $e->getCode(), $e);
43+
throw new FailedToCreateActionLink(
44+
message: 'Failed to create action link: '.$e->getMessage(),
45+
previous: $e
46+
);
4447
}
4548

4649
if ($response->getStatusCode() !== 200) {
@@ -50,7 +53,10 @@ public function handle(CreateActionLink $action): string
5053
try {
5154
$data = Json::decode((string) $response->getBody(), true);
5255
} catch (InvalidArgumentException $e) {
53-
throw new FailedToCreateActionLink('Unable to parse the response data: '.$e->getMessage(), $e->getCode(), $e);
56+
throw new FailedToCreateActionLink(
57+
message: 'Unable to parse the response data: '.$e->getMessage(),
58+
previous: $e
59+
);
5460
}
5561

5662
$actionCode = $data['oobLink'] ?? null;

src/Firebase/Auth/SendActionLink/GuzzleApiClientHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public function handle(SendActionLink $action): void
3939
try {
4040
$response = $this->client->send($request, ['http_errors' => false]);
4141
} catch (ClientExceptionInterface $e) {
42-
throw new FailedToSendActionLink('Failed to send action link: '.$e->getMessage(), $e->getCode(), $e);
42+
throw new FailedToSendActionLink(
43+
message: 'Failed to send action link: '.$e->getMessage(),
44+
previous: $e
45+
);
4346
}
4447

4548
if ($response->getStatusCode() !== 200) {

src/Firebase/Auth/SignIn/FailedToSignIn.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public static function withActionAndResponse(SignIn $action, ResponseInterface $
3737

3838
public static function fromPrevious(Throwable $e): self
3939
{
40-
return new self('Sign in failed: '.$e->getMessage(), $e->getCode(), $e);
40+
return new self(
41+
message: 'Sign in failed: '.$e->getMessage(),
42+
previous: $e
43+
);
4144
}
4245

4346
public function action(): ?SignIn

src/Firebase/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getReference(?string $path = null): Reference
3838
try {
3939
return new Reference($this->uri->withPath($path), $this->client);
4040
} catch (\InvalidArgumentException $e) {
41-
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
41+
throw new InvalidArgumentException(message: $e->getMessage(), previous: $e);
4242
}
4343
}
4444

src/Firebase/Database/Query.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ public function getSnapshot(): Snapshot
8484
} catch (DatabaseNotFound $e) {
8585
throw $e;
8686
} catch (DatabaseException $e) {
87-
throw new UnsupportedQuery($this, $e->getMessage(), $e->getCode(), $e->getPrevious());
87+
throw new UnsupportedQuery(
88+
query: $this,
89+
message: $e->getMessage(),
90+
previous: $e->getPrevious()
91+
);
8892
}
8993

9094
if ($this->sorter !== null) {

src/Firebase/Database/Reference.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function getChild(string $path): self
106106
try {
107107
return new self($this->uri->withPath($childPath), $this->apiClient);
108108
} catch (\InvalidArgumentException $e) {
109-
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
109+
throw new InvalidArgumentException(message: $e->getMessage(), previous: $e);
110110
}
111111
}
112112

src/Firebase/Exception/AppCheckApiExceptionConverter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ public function convertException(Throwable $exception): AppCheckException
2929
}
3030

3131
if ($exception instanceof NetworkExceptionInterface) {
32-
return new ApiConnectionFailed('Unable to connect to the API: '.$exception->getMessage(), $exception->getCode(), $exception);
32+
return new ApiConnectionFailed(
33+
message: 'Unable to connect to the API: '.$exception->getMessage(),
34+
previous: $exception
35+
);
3336
}
3437

35-
return new AppCheckError($exception->getMessage(), $exception->getCode(), $exception);
38+
return new AppCheckError(message: $exception->getMessage(), previous: $exception);
3639
}
3740

3841
private function convertGuzzleRequestException(RequestException $e): AppCheckException

0 commit comments

Comments
 (0)