From da4fb4da191fad7395bb8f13387e992f7e00eb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jun 2019 01:56:41 +0200 Subject: [PATCH] fixup! Use native exception for json functions --- src/Formatter/Json.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Formatter/Json.php b/src/Formatter/Json.php index 7937cbd8..0cb78bc7 100644 --- a/src/Formatter/Json.php +++ b/src/Formatter/Json.php @@ -12,6 +12,8 @@ use const JSON_HEX_TAG; use const JSON_THROW_ON_ERROR; use const JSON_UNESCAPED_SLASHES; +use function assert; +use function is_string; use function json_encode; use function sprintf; @@ -35,7 +37,10 @@ public function __construct(int $flags = self::DEFAULT_FLAGS) public function format($content, array $attributes = []): string { try { - return json_encode($content, $this->flags | JSON_THROW_ON_ERROR); + $content = json_encode($content, $this->flags | JSON_THROW_ON_ERROR); + assert(is_string($content)); + + return $content; } catch (Throwable $exception) { throw new ContentCouldNotBeFormatted( sprintf('An exception was thrown during JSON formatting: %s', $exception->getMessage()),