Json::decode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
nc 2
nop 4
dl 12
loc 12
rs 9.8666
c 1
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: lenovo
5
 * Date: 6/14/2018
6
 * Time: 2:43 PM
7
 */
8
namespace TimSDK\Support;
9
10
use TimSDK\Core\Exceptions\JsonParseException;
11
12
class Json
13
{
14
    /**
15
     * Returns the JSON representation of a value
16
     *
17
     * @static
18
     * @param mixed $value
19
     * @param int   $options
20
     * @param int   $depth
21
     * @return string
22
     * @throws JsonParseException
23
     */
24 View Code Duplication
    public static function encode($value, $options = 0, $depth = 512)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        $json = \json_encode($value, $options, $depth);
27
        if (JSON_ERROR_NONE !== json_last_error()) {
28
            throw new JsonParseException(
29
                'json_encode error: ' . json_last_error_msg(),
30
                json_last_error()
31
            );
32
        }
33
34
        return $json;
35
    }
36
37
    /**
38
     * Decodes a JSON string
39
     *
40
     * @static
41
     * @param string $json
42
     * @param bool   $assoc
43
     * @param int    $depth
44
     * @param int    $options
45
     * @return mixed
46
     * @throws JsonParseException
47
     */
48 View Code Duplication
    public static function decode($json, $assoc = false, $depth = 512, $options = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        $data = \json_decode($json, $assoc, $depth, $options);
51
        if (JSON_ERROR_NONE !== json_last_error()) {
52
            throw new JsonParseException(
53
                'json_decode error: ' . json_last_error_msg(),
54
                json_last_error()
55
            );
56
        }
57
58
        return $data;
59
    }
60
}
61