Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Json
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 encode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 decode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php declare(strict_types=1);
2/**
3 * PrivateBin
4 *
5 * a zero-knowledge paste bin
6 *
7 * @link      https://github.com/PrivateBin/PrivateBin
8 * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
9 * @license   https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
10 */
11
12namespace PrivateBin;
13
14/**
15 * Json
16 *
17 * Provides JSON functions in an object oriented way.
18 */
19class Json
20{
21    /**
22     * Returns a string containing the JSON representation of the given input
23     *
24     * @access public
25     * @static
26     * @param  mixed $input
27     * @throws JsonException
28     * @return string
29     */
30    public static function encode(&$input)
31    {
32        return json_encode($input, JSON_THROW_ON_ERROR);
33    }
34
35    /**
36     * Returns an array with the contents as described in the given JSON input
37     *
38     * @access public
39     * @static
40     * @param  string $input
41     * @throws JsonException
42     * @return mixed
43     */
44    public static function decode(&$input)
45    {
46        return json_decode($input, true, 10, JSON_THROW_ON_ERROR);
47    }
48}