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.

TypeId::fromValue()   D
last analyzed

Complexity

Conditions 10
Paths 10

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 4.8196
c 0
b 0
f 0
cc 10
eloc 20
nc 10
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Pinq\Analysis;
4
5
use Pinq\PinqException;
6
7
/**
8
 * Static helper to generate and interpret type identifiers.
9
 *
10
 * @author Elliot Levin <[email protected]>
11
 */
12
final class TypeId
13
{
14
    private function __construct()
15
    {
16
17
    }
18
19
    public static function getObject($class)
20
    {
21
        return 'object:' . $class;
22
    }
23
24
    public static function isObject($id)
25
    {
26
        return strpos($id, 'object:') === 0;
27
    }
28
29
    public static function getClassTypeFromId($objectId)
30
    {
31
        return substr($objectId, strlen('object:'));
32
    }
33
34
    public static function getComposite(array $typeIds)
35
    {
36
        return 'composite<' . implode('|', $typeIds) . '>';
37
    }
38
39
    public static function isComposite($id)
40
    {
41
        return strpos($id, 'composite<') === 0 && $id[strlen($id) - 1] === '>';
42
    }
43
44
    public static function getComposedTypeIdsFromId($compositeId)
45
    {
46
        return explode('|', substr($compositeId, strlen('composite<'), -strlen('>')));
47
    }
48
49
    public static function fromValue($value)
50
    {
51
        switch (gettype($value)) {
52
            case 'string':
53
                return INativeType::TYPE_STRING;
54
55
            case 'integer':
56
                return INativeType::TYPE_INT;
57
58
            case 'boolean':
59
                return INativeType::TYPE_BOOL;
60
61
            case 'double':
62
                return INativeType::TYPE_DOUBLE;
63
64
            case 'NULL':
65
                return INativeType::TYPE_NULL;
66
67
            case 'array':
68
                return INativeType::TYPE_ARRAY;
69
70
            case 'resource':
71
            case 'unknown type':
72
                return INativeType::TYPE_RESOURCE;
73
74
            case 'object':
75
                return self::getObject(get_class($value));
76
        }
77
78
        throw new PinqException('Unknown variable type %s given', gettype($value));
79
    }
80
}
81