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::jsonLastErrorMsg()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 0
cts 18
cp 0
rs 8.4444
c 0
b 0
f 0
cc 8
nc 8
nop 0
crap 72
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