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.
Completed
Pull Request — master (#65)
by
unknown
01:40
created

JsonType::getType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
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
     * @var TypeInterface
12
     */
13
    private static $instance;
14
15
    public static function getType()
16
    {
17
        if (!isset(self::$instance)) {
18
            self::$instance = new JsonType();
19
        }
20
21
        return self::$instance;
22
    }
23
24
    /**
25
     * Filter a value to be a Json
26
     *
27
     * @param  string                              $value
28
     * @param  null                                $annotation Unused
29
     * @throws \Minime\Annotations\ParserException
30
     * @return mixed
31
     */
32
    public function parse($value, $annotation = null)
33
    {
34
        $json = static::jsonDecode($value);
35
        if (JSON_ERROR_NONE != json_last_error()) {
36
            throw new ParserException("Raw value must be a valid JSON string. Invalid value '{$value}' given.");
37
        }
38
39
        return $json;
40
    }
41
42
    /**
43
     * Wrapper fo json_decode function that keeps parser portable
44
     * between json-ext and pecl-json-c extensions
45
     *
46
     * @param  string $value json string
47
     * @return mixed
48
     */
49
    public static function jsonDecode($value)
50
    {
51
        if (defined('JSON_PARSER_NOTSTRICT')) { // pecl-json-c ext
52
            $decoded = json_decode($value, false, 512, JSON_PARSER_NOTSTRICT);
53
        } else { // json-ext
54
            $decoded = json_decode($value);
55
        }
56
57
        return $decoded;
58
    }
59
60
}
61