InvalidJSON   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A getErrorMessage() 0 17 6
1
<?php
2
3
namespace BeyondCode\Credentials\Exceptions;
4
5
use Exception;
6
7
class InvalidJSON extends Exception
8
{
9
    /**
10
     * Create a new InvalidJson exception instance.
11
     *
12
     * @param int $error
13
     * @return $this
14
     */
15
    public static function create($error)
16
    {
17
        return new static("Unable to parse credential JSON ".self::getErrorMessage($error));
18
    }
19
20
    /**
21
     * Get the error message.
22
     *
23
     * @param int $error
24
     * @return string
25
     */
26
    private static function getErrorMessage($error)
27
    {
28
        switch ($error) {
29
            case JSON_ERROR_DEPTH:
30
                return ' - Maximum stack depth exceeded';
31
            case JSON_ERROR_STATE_MISMATCH:
32
                return ' - Underflow or the modes mismatch';
33
            case JSON_ERROR_CTRL_CHAR:
34
                return ' - Unexpected control character found';
35
            case JSON_ERROR_SYNTAX:
36
                return ' - Syntax error, malformed JSON';
37
            case JSON_ERROR_UTF8:
38
                return ' - Malformed UTF-8 characters, possibly incorrectly encoded';
39
            default:
40
                return ' - Unknown error';
41
        }
42
    }
43
}
44