Lines 0.00% 0 / 2
Functions and Methods 0.00% 0 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
JsonEncoder 0.00% 0 / 2 0.00% 0 / 2 6 0.00% 0 / 1
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 encodeToJson 0.00% 0 / 1 0.00% 0 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Support\Json;
6
7use JsonException;
8
9/** @internal */
10final class JsonEncoder
11{
12    private const int ENCODE_FLAGS = \JSON_THROW_ON_ERROR
13        | \JSON_PRESERVE_ZERO_FRACTION
14        | \JSON_UNESCAPED_UNICODE
15        | \JSON_UNESCAPED_SLASHES
16        | \JSON_INVALID_UTF8_SUBSTITUTE;
17
18    private function __construct() {}
19
20    /**
21     * @param int<1, max> $depth
22     * @throws JsonException
23     */
24    public static function encodeToJson(mixed $value, int $depth = 512): string
25    {
26        return json_encode($value, self::ENCODE_FLAGS, $depth);
27    }
28}