From 9d3434e57ce4d938319c0fa11a776aa8905c582e Mon Sep 17 00:00:00 2001 From: Joan Miquel Date: Mon, 11 Dec 2023 11:26:10 +0100 Subject: [PATCH] refactor: use json_decode exception (#374) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- src/Shared/Domain/Utils.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Shared/Domain/Utils.php b/src/Shared/Domain/Utils.php index 7939ff26b..443c406e0 100644 --- a/src/Shared/Domain/Utils.php +++ b/src/Shared/Domain/Utils.php @@ -6,7 +6,6 @@ use DateTimeImmutable; use DateTimeInterface; -use RuntimeException; use function Lambdish\Phunctional\filter; final class Utils @@ -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