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.

TypeHint   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
dl 0
loc 56
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 12 2
A isScalarType() 0 8 1
A isArray() 0 3 2
A getArrayType() 0 8 3
1
<?php
2
3
namespace PhpBoot\Utils;
4
5
use phpDocumentor\Reflection\TypeResolver;
6
use phpDocumentor\Reflection\Types\ContextFactory;
7
8
class TypeHint
9
{
10
    /**
11
     * 标准化类型
12
     * 1. 基本类型, 转换成规范的拼写, 如double -> float, integer -> int
13
     * 2. 对象类型, 补全namespace
14
     * @param string $type 需要标准化的字符串
15
     * @param  string $contextClass 当前上下文所在的类,一般传__CLASS__, 用于扫描当前文件的use信息, 以便拼上namespace
16
     */
17 21
    static function normalize($type, $contextClass=null){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
18 21
        $resolver = new TypeResolver();
19 21
        $context = null;
20 21
        if($contextClass){
0 ignored issues
show
Bug Best Practice introduced by
The expression $contextClass of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
21
            //TODO 优化性能
22 21
            $contextFactory = new ContextFactory();
23 21
            $context = $contextFactory->createFromReflector(new \ReflectionClass($contextClass));
24 21
        }
25 21
        $type = $resolver->resolve($type, $context);
26 21
        $type = ltrim($type, '\\');
27 21
        return (string)$type;
28
    }
29
    /**
30
     * 是否是基本类型
31
     * @param string $type
32
     */
33 14
    static function isScalarType($type){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34 14
        return in_array($type, [
35 14
            'bool',
36 14
            'int',
37 14
            'float',
38
            'string'
39 14
        ]);
40
    }
41
42
    /**
43
     * @param $type
44
     * @return bool
45
     */
46 10
    static function isArray($type){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
47 10
        return ($type == 'array' || substr($type, -2) == '[]');
48
    }
49
50
    /**
51
     * 获取数组的类型
52
     * @param $type
53
     * @return string|null
54
     */
55 6
    static function getArrayType($type){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56 6
        self::isArray($type) or \PhpBoot\abort(new \InvalidArgumentException("$type is not array"));
57 6
        if($type == 'array') {
58
            return 'mixed';
59
        }else{
60 6
            return substr($type,0,-2);
61
        }
62
    }
63
}