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.

Type   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 79
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B cast() 0 28 7
A isValidType() 0 15 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Patoui\Router;
6
7
class Type
8
{
9
    public const TYPE_INT     = 'int';
10
    public const TYPE_INTEGER = 'integer';
11
    public const TYPE_BOOL    = 'bool';
12
    public const TYPE_BOOLEAN = 'boolean';
13
    public const TYPE_FLOAT   = 'float';
14
    public const TYPE_DOUBLE  = 'double';
15
    public const TYPE_REAL    = 'real';
16
    public const TYPE_STRING  = 'string';
17
    public const TYPE_ARRAY   = 'array';
18
    public const TYPE_OBJECT  = 'object';
19
20
    public const INTEGER_TYPES = [
21
        self::TYPE_INT,
22
        self::TYPE_INTEGER,
23
    ];
24
25
    public const BOOLEAN_TYPES = [
26
        self::TYPE_BOOL,
27
        self::TYPE_BOOLEAN,
28
    ];
29
30
    public const FLOAT_TYPES = [
31
        self::TYPE_FLOAT,
32
        self::TYPE_DOUBLE,
33
        self::TYPE_REAL,
34
    ];
35
36
    /**
37
     * @param string $type
38
     * @param mixed $value
39
     * @return mixed
40
     */
41
    public static function cast(string $type, $value)
42
    {
43
        if (in_array($type, self::INTEGER_TYPES, true)) {
44
            return (int) $value;
45
        }
46
47
        if (in_array($type, self::BOOLEAN_TYPES, true)) {
48
            return (bool) $value;
49
        }
50
51
        if (in_array($type, self::FLOAT_TYPES, true)) {
52
            return (float) $value;
53
        }
54
55
        if ($type === self::TYPE_STRING) {
56
            return (string) $value;
57
        }
58
59
        if ($type === self::TYPE_ARRAY) {
60
            return (array) $value;
61
        }
62
63
        if ($type === self::TYPE_OBJECT) {
64
            return (object) $value;
65
        }
66
67
        return $value;
68
    }
69
70
    public static function isValidType(string $type): bool
71
    {
72
        return in_array($type, [
73
            self::TYPE_INT,
74
            self::TYPE_INTEGER,
75
            self::TYPE_BOOL,
76
            self::TYPE_BOOLEAN,
77
            self::TYPE_FLOAT,
78
            self::TYPE_DOUBLE,
79
            self::TYPE_REAL,
80
            self::TYPE_STRING,
81
            self::TYPE_ARRAY,
82
            self::TYPE_OBJECT,
83
        ], true);
84
    }
85
}
86