Skip to content

Commit

Permalink
refactor: use json_decode exception (#374)
Browse files Browse the repository at this point in the history
* Use json_decode exception

Ahora es más rápido.

Lo curioso es que si lo usan el jsonEncode().

Fix: #373

* fix: remove unused import

---------

Co-authored-by: Javier Ferrer González <[email protected]>
  • Loading branch information
joanhey and JavierCane authored Dec 11, 2023
1 parent faf1a6a commit 9d3434e
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/Shared/Domain/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use DateTimeImmutable;
use DateTimeInterface;
use RuntimeException;
use function Lambdish\Phunctional\filter;

final class Utils
Expand Down Expand Up @@ -38,13 +37,7 @@ public static function jsonEncode(array $values): string

public static function jsonDecode(string $json): array
{
$data = json_decode($json, true);

if (json_last_error() !== JSON_ERROR_NONE) {
throw new RuntimeException('Unable to parse response body into JSON: ' . json_last_error());
}

return $data;
return json_decode($json, true, flags: JSON_THROW_ON_ERROR);
}

public static function toSnakeCase(string $text): string
Expand Down

0 comments on commit 9d3434e

Please sign in to comment.