Types   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 86
ccs 0
cts 48
cp 0
rs 10
c 0
b 0
f 0
wmc 26
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
C getTypeName() 0 29 12
A getTypeByValue() 0 4 1
C getType() 0 30 13
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Compiler;
7
8
use PHPSA\CompiledExpression;
9
use RuntimeException;
10
11
class Types
12
{
13
    /**
14
     * Get name for the $type
15
     *
16
     * @param integer $type
17
     * @return string
18
     */
19
    public static function getTypeName($type)
20
    {
21
        switch ($type) {
22
            case CompiledExpression::INTEGER:
23
                return 'integer';
24
            case CompiledExpression::DOUBLE:
25
                return 'double';
26
            case CompiledExpression::STRING:
27
                return 'string';
28
            case CompiledExpression::NUMBER:
29
                return 'number';
30
            case CompiledExpression::ARR:
31
                return 'array';
32
            case CompiledExpression::OBJECT:
33
                return 'object';
34
            case CompiledExpression::RESOURCE:
35
                return 'resource';
36
            case CompiledExpression::CALLABLE_TYPE:
37
                return 'callable';
38
            case CompiledExpression::BOOLEAN:
39
                return 'boolean';
40
            case CompiledExpression::NULL:
41
                return 'null';
42
            case CompiledExpression::MIXED:
43
                return 'mixed';
44
            default:
45
                return 'unknown';
46
        }
47
    }
48
49
    /**
50
     * Get type by $value
51
     *
52
     * @param $value
53
     * @return int
54
     */
55
    public static function getTypeByValue($value)
56
    {
57
        return self::getType(gettype($value));
58
    }
59
60
    /**
61
     * Get type (integer) by $type
62
     *
63
     * @param string $typeName
64
     * @return int
65
     */
66
    public static function getType($typeName)
67
    {
68
        switch ($typeName) {
69
            case 'integer':
70
            case 'int':
71
                return CompiledExpression::INTEGER;
72
            case 'float':
73
            case 'double':
74
                return CompiledExpression::DOUBLE;
75
            case 'string':
76
                return CompiledExpression::STRING;
77
            case 'resource':
78
                return CompiledExpression::RESOURCE;
79
            case 'callable':
80
                return CompiledExpression::CALLABLE_TYPE;
81
            case 'object':
82
                return CompiledExpression::OBJECT;
83
            case 'array':
84
                return CompiledExpression::ARR;
85
            case 'boolean':
86
            case 'bool':
87
                return CompiledExpression::BOOLEAN;
88
            case 'NULL':
89
                return CompiledExpression::NULL;
90
        }
91
92
        //@codeCoverageIgnoreStart
93
        throw new RuntimeException("Type '{$typeName}' is not supported");
94
        //@codeCoverageIgnoreEnd
95
    }
96
}
97