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
Push — master ( 1a4436...5d2a83 )
by SignpostMarv
02:54
created

JsonTypeUtilities   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A ThrowBecauseArrayJsonTypeNotValid() 0 9 2
A FilterThrowIfJsonDefNotValid() 0 14 2
A MakeMapperThrowIfJsonDefNotValid() 0 18 3
A ThrowIfNotDaftJson() 0 4 2
A ThrowIfNotJsonType() 0 4 2
1
<?php
2
/**
3
* @author SignpostMarv
4
*/
5
declare(strict_types=1);
6
7
namespace SignpostMarv\DaftObject;
8
9
use Closure;
10
11
class JsonTypeUtilities
12
{
13 164
    public static function ThrowIfNotDaftJson(string $class) : void
14
    {
15 164
        if (false === is_a($class, DaftJson::class, true)) {
16 128
            throw new DaftObjectNotDaftJsonBadMethodCallException($class);
17
        }
18 36
    }
19
20 10
    public static function ThrowIfNotJsonType(string $jsonType) : void
21
    {
22 10
        if (false === is_a($jsonType, DaftJson::class, true)) {
23 2
            throw new ClassDoesNotImplementClassException($jsonType, DaftJson::class);
24
        }
25 8
    }
26
27 22
    public static function MakeMapperThrowIfJsonDefNotValid(
28
        string $class,
29
        array $jsonDef,
30
        array $array
31
    ) : Closure {
32
        $mapper =
33
            /**
34
            * @return mixed
35
            */
36
            function (string $prop) use ($jsonDef, $array, $class) {
37 20
                if (isset($jsonDef[$prop]) && false === is_array($array[$prop])) {
38 4
                    static::ThrowBecauseArrayJsonTypeNotValid($class, $jsonDef[$prop], $prop);
39
                }
40
41 16
                return $array[$prop];
42 22
            };
43
44 22
        return $mapper;
45
    }
46
47 24
    public static function FilterThrowIfJsonDefNotValid(
48
        string $class,
49
        array $jsonProps,
50
        array $array
51
    ) : array {
52
        $filter = function (string $prop) use ($jsonProps, $array, $class) : bool {
53 24
            if (false === in_array($prop, $jsonProps, true)) {
54 2
                throw new PropertyNotJsonDecodableException($class, $prop);
55
            }
56
57 24
            return false === is_null($array[$prop]);
58 24
        };
59
60 24
        return array_filter($array, $filter, ARRAY_FILTER_USE_KEY);
61
    }
62
63 4
    private static function ThrowBecauseArrayJsonTypeNotValid(
64
        string $class,
65
        string $type,
66
        string $prop
67
    ) : void {
68 4
        if ('[]' === mb_substr($type, -2)) {
69 2
            throw new PropertyNotJsonDecodableShouldBeArrayException($class, $prop);
70
        }
71 2
        throw new PropertyNotJsonDecodableShouldBeArrayException($type, $prop);
72
    }
73
}
74