Skip to content

Commit

Permalink
fix invalid return type
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Jan 19, 2025
1 parent 1902497 commit da06e3f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,20 @@ public static function maybeDecode(string $string): Maybe
public static function encode(mixed $content, int $options = 0, int $depth = 512): string
{
try {
return \json_encode(
$content = \json_encode(
$content,
$options | \JSON_THROW_ON_ERROR,
$depth,
);

if ($content === false) {
// This case should not happen since we use the option to throw
// on error. But Psalm doesn't understand that so we have to
// handle the `false` case.
throw new \JsonException;
}

return $content;
} catch (\JsonException $e) {
throw self::wrap($e);
}
Expand Down

0 comments on commit da06e3f

Please sign in to comment.