Passed
Push — master ( 29dcbf...f16479 )
by Nicolas
02:21
created

Json::encode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Puzzle\Pieces;
4
5
class Json
6
{
7 5
    public static function decode($json, $assoc = false, $depth = 512, $option = 0)
8
    {
9 5
        $decodedJson = json_decode($json, $assoc, $depth, $option);
10
11 5
        $jsonLastError = json_last_error();
12 5
        if($jsonLastError != JSON_ERROR_NONE)
13 5
        {
14 5
            throw new Exceptions\JsonDecodeError(json_last_error_msg());
15
        }
16
17
        return $decodedJson;
18
    }
19
20 4
    public static function encode($value, $option = 0, $depth = 512)
21
    {
22 4
        $json = json_encode($value, $option, $depth);
23
24 4
        if($json === false)
25 4
        {
26 2
            throw new Exceptions\JsonEncodeError(json_last_error_msg());
27
        }
28
29 2
        return $json;
30
    }
31
}
32