TypeHintReference::isBuiltInParamTypeHint()   B
last analyzed

Complexity

Conditions 10
Paths 10

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 7.6666
c 0
b 0
f 0
cc 10
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 Prophecy\Doubler\Generator;
4
5
/**
6
 * Tells whether a keyword refers to a class or to a built-in type for the
7
 * current version of php
8
 */
9
final class TypeHintReference
10
{
11
    public function isBuiltInParamTypeHint($type)
12
    {
13
        switch ($type) {
14
            case 'self':
15
            case 'array':
16
                return true;
17
18
            case 'callable':
19
                return PHP_VERSION_ID >= 50400;
20
21
            case 'bool':
22
            case 'float':
23
            case 'int':
24
            case 'string':
25
                return PHP_VERSION_ID >= 70000;
26
27
            case 'iterable':
28
                return PHP_VERSION_ID >= 70100;
29
30
            case 'object':
31
                return PHP_VERSION_ID >= 70200;
32
33
            default:
34
                return false;
35
        }
36
    }
37
38
    public function isBuiltInReturnTypeHint($type)
39
    {
40
        if ($type === 'void') {
41
            return PHP_VERSION_ID >= 70100;
42
        }
43
44
        return $this->isBuiltInParamTypeHint($type);
45
    }
46
}
47