CodelyTV / php-ddd-example

🐘🎯 Hexagonal Architecture + DDD + CQRS in PHP using Symfony 6

Home Page:https://pro.codely.tv/library/ddd-en-php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

json_encode() y json_decode() puede lanzar exception desde PHP 7.3

joanhey opened this issue · comments

Info:
https://www.php.net/manual/en/class.jsonexception
https://wiki.php.net/rfc/json_throw_on_error

Este código sobra o se puede reducir a 1 línea.

public static function jsonDecode(string $json): array
{
$data = json_decode($json, true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new RuntimeException('Unable to parse response body into JSON: ' . json_last_error());
}
return $data;

Lo vi en vuestro video https://youtu.be/hXCT1jZt3vQ?t=3606
No es necesario esperar a json_decode2().