Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Exceptions/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
/**
* Creates a new Exception instance.
*
* @param array{message: string|array<int, string>, type: ?string, code: string|int|null} $contents
* @param string|array{message: string|array<int, string>, type: ?string, code: string|int|null} $contents
*/
public function __construct(private readonly array $contents, private readonly int $statusCode)
public function __construct(private readonly string|array $contents, private readonly int $statusCode)
{
$message = ($contents['message'] ?: (string) $this->contents['code']) ?: 'Unknown error';
$message = is_array($this->contents)
? (($contents['message'] ?: (string) $this->contents['code']) ?: 'Unknown error')

Check failure on line 19 in src/Exceptions/ErrorException.php

View workflow job for this annotation

GitHub Actions / Formats P8.2 - ubuntu-latest - prefer-lowest

Offset 'message' does not exist on array{message: array<int, string>|string, type: string|null, code: int|string|null}|string.

Check failure on line 19 in src/Exceptions/ErrorException.php

View workflow job for this annotation

GitHub Actions / Formats P8.2 - ubuntu-latest - prefer-stable

Offset 'message' does not exist on array{message: array<int, string>|string, type: string|null, code: int|string|null}|string.
: $this->contents;

if (is_array($message)) {
$message = implode(PHP_EOL, $message);
Expand Down Expand Up @@ -47,7 +49,7 @@
*/
public function getErrorType(): ?string
{
return $this->contents['type'];

Check failure on line 52 in src/Exceptions/ErrorException.php

View workflow job for this annotation

GitHub Actions / Formats P8.2 - ubuntu-latest - prefer-lowest

Offset 'type' does not exist on array{message: array<int, string>|string, type: string|null, code: int|string|null}|string.

Check failure on line 52 in src/Exceptions/ErrorException.php

View workflow job for this annotation

GitHub Actions / Formats P8.2 - ubuntu-latest - prefer-stable

Offset 'type' does not exist on array{message: array<int, string>|string, type: string|null, code: int|string|null}|string.
}

/**
Expand All @@ -55,6 +57,6 @@
*/
public function getErrorCode(): string|int|null
{
return $this->contents['code'];

Check failure on line 60 in src/Exceptions/ErrorException.php

View workflow job for this annotation

GitHub Actions / Formats P8.2 - ubuntu-latest - prefer-lowest

Offset 'code' does not exist on array{message: array<int, string>|string, type: string|null, code: int|string|null}|string.

Check failure on line 60 in src/Exceptions/ErrorException.php

View workflow job for this annotation

GitHub Actions / Formats P8.2 - ubuntu-latest - prefer-stable

Offset 'code' does not exist on array{message: array<int, string>|string, type: string|null, code: int|string|null}|string.
}
}
2 changes: 1 addition & 1 deletion src/Responses/StreamResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getIterator(): Generator
break;
}

/** @var array{error?: array{message: string|array<int, string>, type: string, code: string}, type?: string} $response */
/** @var array{error?: string|array{message: string|array<int, string>, type: string, code: string}, type?: string} $response */
$response = json_decode($data, true, flags: JSON_THROW_ON_ERROR);

if (isset($response['error'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Transporters/HttpTransporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function requestObject(Payload $payload): Response
$this->throwIfJsonError($response, $contents);

try {
/** @var array{error?: array{message: string, type: string, code: string}} $data */
/** @var array{error?: string|array{message: string, type: string, code: string}} $data */
$data = json_decode($contents, true, flags: JSON_THROW_ON_ERROR);
} catch (JsonException $jsonException) {
throw new UnserializableResponse($jsonException);
Expand Down Expand Up @@ -126,7 +126,7 @@ private function throwIfJsonError(ResponseInterface $response, string|ResponseIn
}

try {
/** @var array{error?: array{message: string|array<int, string>, type: string, code: string}} $response */
/** @var array{error?: string|array{message: string|array<int, string>, type: string, code: string}} $response */
$response = json_decode($contents, true, flags: JSON_THROW_ON_ERROR);

if (isset($response['error'])) {
Expand Down
Loading