a few fixes from Copilot review

pull/657/head
n0nag0n 1 day ago
parent 3d0599eb67
commit eecbdc3895

@ -41,7 +41,7 @@ class Json
try { try {
return json_encode($data, $options, $depth); return json_encode($data, $options, $depth);
} catch (JsonException $e) { } catch (JsonException $e) {
throw new JsonException('JSON encoding failed: ' . $e->getMessage(), $e->getCode(), $e); throw new Exception('JSON encoding failed: ' . $e->getMessage(), $e->getCode(), $e);
} }
} }
@ -56,13 +56,13 @@ class Json
* @return mixed Decoded data * @return mixed Decoded data
* @throws Exception If decoding fails * @throws Exception If decoding fails
*/ */
public static function decode(string $json, bool $associative = false, int $depth = 512, int $options = self::DEFAULT_DECODE_OPTIONS) public static function decode(string $json, bool $associative = false, int $depth = 512, int $options = 0)
{ {
$options = $options | self::DEFAULT_DECODE_OPTIONS; // Ensure default options are applied $options = $options | self::DEFAULT_DECODE_OPTIONS; // Ensure default options are applied
try { try {
return json_decode($json, $associative, $depth, $options); return json_decode($json, $associative, $depth, $options);
} catch (JsonException $e) { } catch (JsonException $e) {
throw new JsonException('JSON decoding failed: ' . $e->getMessage(), $e->getCode(), $e); throw new Exception('JSON decoding failed: ' . $e->getMessage(), $e->getCode(), $e);
} }
} }

@ -398,7 +398,7 @@ class EngineTest extends TestCase
public function testJsonThrowOnErrorByDefault() public function testJsonThrowOnErrorByDefault()
{ {
$engine = new Engine(); $engine = new Engine();
$this->expectException(JsonException::class); $this->expectException(Exception::class);
$this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded'); $this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded');
$engine->json(['key1' => 'value1', 'key2' => 'value2', 'utf8_emoji' => "\xB1\x31"]); $engine->json(['key1' => 'value1', 'key2' => 'value2', 'utf8_emoji' => "\xB1\x31"]);
} }

Loading…
Cancel
Save