Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Mar 23, 2024
1 parent df50533 commit 55b9dc8
Showing 1 changed file with 53 additions and 74 deletions.
127 changes: 53 additions & 74 deletions src/Json.php
Expand Up @@ -85,79 +85,58 @@ public static function encode($content, int $options = 0, int $depth = 512): str
*/
private static function wrap(\JsonException $e): \Exception
{
switch ($e->getCode()) {
case \JSON_ERROR_DEPTH:
return new MaximumDepthExceeded(
$e->getMessage(),
0,
$e,
);

case \JSON_ERROR_STATE_MISMATCH:
return new StateMismatch(
$e->getMessage(),
0,
$e,
);

case \JSON_ERROR_CTRL_CHAR:
return new CharacterControlError(
$e->getMessage(),
0,
$e,
);

case \JSON_ERROR_SYNTAX:
return new SyntaxError(
$e->getMessage(),
0,
$e,
);

case \JSON_ERROR_UTF8:
return new MalformedUTF8(
$e->getMessage(),
0,
$e,
);

case \JSON_ERROR_RECURSION:
return new RecursiveReference(
$e->getMessage(),
0,
$e,
);

case \JSON_ERROR_INF_OR_NAN:
return new InfiniteOrNanCannotBeEncoded(
$e->getMessage(),
0,
$e,
);

case \JSON_ERROR_UNSUPPORTED_TYPE:
return new ValueCannotBeEncoded(
$e->getMessage(),
0,
$e,
);

case \JSON_ERROR_INVALID_PROPERTY_NAME:
return new PropertyCannotBeEncoded(
$e->getMessage(),
0,
$e,
);

case \JSON_ERROR_UTF16:
return new MalformedUTF16(
$e->getMessage(),
0,
$e,
);

default:
return $e;
}
return match ($e->getCode()) {
\JSON_ERROR_DEPTH => new MaximumDepthExceeded(
$e->getMessage(),
0,
$e,
),
\JSON_ERROR_STATE_MISMATCH => new StateMismatch(
$e->getMessage(),
0,
$e,
),
\JSON_ERROR_CTRL_CHAR => new CharacterControlError(
$e->getMessage(),
0,
$e,
),
\JSON_ERROR_SYNTAX => new SyntaxError(
$e->getMessage(),
0,
$e,
),
\JSON_ERROR_UTF8 => new MalformedUTF8(
$e->getMessage(),
0,
$e,
),
\JSON_ERROR_RECURSION => new RecursiveReference(
$e->getMessage(),
0,
$e,
),
\JSON_ERROR_INF_OR_NAN => new InfiniteOrNanCannotBeEncoded(
$e->getMessage(),
0,
$e,
),
\JSON_ERROR_UNSUPPORTED_TYPE => new ValueCannotBeEncoded(
$e->getMessage(),
0,
$e,
),
\JSON_ERROR_INVALID_PROPERTY_NAME => new PropertyCannotBeEncoded(
$e->getMessage(),
0,
$e,
),
\JSON_ERROR_UTF16 => new MalformedUTF16(
$e->getMessage(),
0,
$e,
),
default => $e,
};
}
}

0 comments on commit 55b9dc8

Please sign in to comment.