Passed
Push — master ( 4bcd98...bef579 )
by 世昌
03:04
created

JsonException::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 3
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
namespace suda\framework\exception;
3
4
use RuntimeException;
5
use Throwable;
6
7
/**
8
 * json置类
9
 */
10
class JsonException extends RuntimeException
11
{
12
    public static $error=[
13
        JSON_ERROR_NONE=>'no errors',
14
        JSON_ERROR_DEPTH=>'maximum stack depth exceeded',
15
        JSON_ERROR_STATE_MISMATCH=>'underflow or the modes mismatch',
16
        JSON_ERROR_CTRL_CHAR=>'unexpected control character found',
17
        JSON_ERROR_SYNTAX=>'syntax error, malformed JSON',
18
        JSON_ERROR_UTF8=>'malformed UTF-8 characters, possibly incorrectly encoded',
19
    ];
20
21
    public function __construct($message = "", $code = 0, Throwable $previous = null)
22
    {
23
        if (array_key_exists($code, static::$error)) {
24
            $message = static::$error[$code].' : '.$message;
25
        }
26
        parent::__construct($message, $code, $previous);
27
    }
28
}
29