Skip to content

Commit 9d3434e

Browse files
joanheyJavierCane
andauthored
refactor: use json_decode exception (#374)
* 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 <javier.ferrer@codely.com>
1 parent faf1a6a commit 9d3434e

1 file changed

Lines changed: 1 addition & 8 deletions

File tree

src/Shared/Domain/Utils.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use DateTimeImmutable;
88
use DateTimeInterface;
9-
use RuntimeException;
109
use function Lambdish\Phunctional\filter;
1110

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

3938
public static function jsonDecode(string $json): array
4039
{
41-
$data = json_decode($json, true);
42-
43-
if (json_last_error() !== JSON_ERROR_NONE) {
44-
throw new RuntimeException('Unable to parse response body into JSON: ' . json_last_error());
45-
}
46-
47-
return $data;
40+
return json_decode($json, true, flags: JSON_THROW_ON_ERROR);
4841
}
4942

5043
public static function toSnakeCase(string $text): string

0 commit comments

Comments
 (0)