GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( ce9742...4c1af4 )
by sunsky
11:33
created

Json   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 1
dl 0
loc 52
ccs 6
cts 24
cp 0.25
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 4 1
A decode() 0 6 2
B jsonLastErrorMsg() 0 26 8
1
<?php
2
/**
3
 *
4
 * @author  [email protected] [email protected]
5
 * Date: 2017/6/16
6
 * Time: 10:02
7
 * @version $Id: $
8
 * @since 1.0
9
 * @copyright Sina Corp.
10
 */
11
12
namespace MultiHttp\Handler;
13
14
use MultiHttp\Exception\UnexpectedResponseException;
15
16
/**
17
 * @package MultiHttp
18
 */
19
class Json implements IHandler
20
{
21
    /**
22
     * @param $body
23
     * @return string
24
     */
25 2
    public function encode($body)
26
    {
27 2
        return json_encode($body, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
28
    }
29
30
    /**
31
     * @param $body
32
     * @return mixed
33
     */
34 2
    public function decode($body)
35
    {
36 2
        $parsed = json_decode($body, true);
37 2
        if(json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '.  self::jsonLastErrorMsg() . ', raw body: ' .$body  );
38 2
        return $parsed;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    private static function jsonLastErrorMsg(){
45
        if(function_exists('json_last_error_msg')) return json_last_error_msg();
46
        switch (json_last_error()) {
47
            case JSON_ERROR_NONE:
48
                return ' - No errors';
49
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
50
            case JSON_ERROR_DEPTH:
51
                return ' - Maximum stack depth exceeded';
52
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
53
            case JSON_ERROR_STATE_MISMATCH:
54
                return ' - Underflow or the modes mismatch';
55
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
56
            case JSON_ERROR_CTRL_CHAR:
57
                return ' - Unexpected control character found';
58
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
59
            case JSON_ERROR_SYNTAX:
60
                return ' - Syntax error, malformed JSON';
61
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
62
            case JSON_ERROR_UTF8:
63
                return ' - Malformed UTF-8 characters, possibly incorrectly encoded';
64
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
65
            default:
66
                return ' - Unknown error';
67
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
68
        }
69
    }
70
}
71
72