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
02:16
created

JsonType   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
cbo 2
dl 0
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 8 2
A parse() 0 9 2
A jsonDecode() 0 10 2
1
<?php
2
3
namespace Minime\Annotations\Types;
4
5
use Minime\Annotations\ParserException;
6
7
class JsonType extends AbstractType
8
{
9
    /**
10
     * @var TypeInterface
11
     */
12
    private static $instance;
13
14
    public static function getType()
15
    {
16
        if (!isset(self::$instance)) {
17
            self::$instance = new JsonType();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Minime\Annotations\Types\JsonType() of type object<Minime\Annotations\Types\JsonType> is incompatible with the declared type object<Minime\Annotations\Types\TypeInterface> of property $instance.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
18
        }
19
20
        return self::$instance;
0 ignored issues
show
Bug Compatibility introduced by
The expression self::$instance; of type Minime\Annotations\Types...ons\Types\TypeInterface adds the type Minime\Annotations\Types\TypeInterface to the return on line 20 which is incompatible with the return type declared by the abstract method Minime\Annotations\Types\AbstractType::getType of type Minime\Annotations\Interfaces\TypeInterface.
Loading history...
21
    }
22
23
    /**
24
     * Filter a value to be a Json
25
     *
26
     * @param  string                              $value
27
     * @param  null                                $annotation Unused
28
     * @throws \Minime\Annotations\ParserException
29
     * @return mixed
30
     */
31
    public function parse($value, $annotation = null)
32
    {
33
        $json = static::jsonDecode($value);
34
        if (JSON_ERROR_NONE != json_last_error()) {
35
            throw new ParserException("Raw value must be a valid JSON string. Invalid value '{$value}' given.");
36
        }
37
38
        return $json;
39
    }
40
41
    /**
42
     * Wrapper fo json_decode function that keeps parser portable
43
     * between json-ext and pecl-json-c extensions
44
     *
45
     * @param  string $value json string
46
     * @return mixed
47
     */
48
    public static function jsonDecode($value)
49
    {
50
        if (defined('JSON_PARSER_NOTSTRICT')) { // pecl-json-c ext
51
            $decoded = json_decode($value, false, 512, JSON_PARSER_NOTSTRICT);
52
        } else { // json-ext
53
            $decoded = json_decode($value);
54
        }
55
56
        return $decoded;
57
    }
58
59
}
60