Completed
Pull Request — master (#1)
by Claude
02:42
created

Json   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 29
c 0
b 0
f 0
ccs 13
cts 14
cp 0.9286
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decode() 0 12 2
A encode() 0 13 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
            $jsonLastError = json_last_error();
0 ignored issues
show
Unused Code introduced by
$jsonLastError is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
27
28 2
            throw new Exceptions\JsonEncodeError(json_last_error_msg());
29
        }
30
31 2
        return $json;
32
    }
33
}
34