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.

JsonType::jsonDecode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Minime\Annotations\Types;
4
5
use Minime\Annotations\Interfaces\TypeInterface;
6
use Minime\Annotations\ParserException;
7
8
class JsonType implements TypeInterface
9
{
10
11
    /**
12
     * Filter a value to be a Json
13
     *
14
     * @param  string                              $value
15
     * @param  null                                $annotation Unused
16
     * @throws \Minime\Annotations\ParserException
17
     * @return mixed
18
     */
19
    public function parse($value, $annotation = null)
20
    {
21
        $json = static::jsonDecode($value);
22
        if (JSON_ERROR_NONE != json_last_error()) {
23
            throw new ParserException("Raw value must be a valid JSON string. Invalid value '{$value}' given.");
24
        }
25
26
        return $json;
27
    }
28
29
    /**
30
     * Wrapper fo json_decode function that keeps parser portable
31
     * between json-ext and pecl-json-c extensions
32
     *
33
     * @param  string $value json string
34
     * @return mixed
35
     */
36
    public static function jsonDecode($value)
37
    {
38
        if (defined('JSON_PARSER_NOTSTRICT')) { // pecl-json-c ext
39
            $decoded = json_decode($value, false, 512, JSON_PARSER_NOTSTRICT);
40
        } else { // json-ext
41
            $decoded = json_decode($value);
42
        }
43
44
        return $decoded;
45
    }
46
47
}
48