Kint_Object_Parameter::__construct()   C
last analyzed

Complexity

Conditions 14
Paths 98

Size

Total Lines 46
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 33
nc 98
nop 1
dl 0
loc 46
rs 5.0744
c 0
b 0
f 0

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
class Kint_Object_Parameter extends Kint_Object
0 ignored issues
show
Coding Style introduced by
Kint_Object_Parameter does not seem to conform to the naming convention (^[A-Z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
The property $type_hint is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
4
{
5
    public $type_hint = null;
0 ignored issues
show
Coding Style introduced by
$type_hint does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
6
    public $default = null;
7
    public $position = null;
8
    public $hints = array('parameter');
9
10
    public function getType()
11
    {
12
        return $this->type_hint;
13
    }
14
15
    public function getName()
16
    {
17
        return '$'.$this->name;
18
    }
19
20
    public function __construct(ReflectionParameter $param)
21
    {
22
        if (method_exists('ReflectionParameter', 'getType')) {
23
            if ($type = $param->getType()) {
24
                $this->type_hint = (string) $type;
25
            }
26
        } else {
27
            if ($param->isArray()) {
28
                $this->type_hint = 'array';
29
            } else {
30
                try {
31
                    if ($this->type_hint = $param->getClass()) {
32
                        $this->type_hint = $this->type_hint->name;
33
                    }
34
                } catch (ReflectionException $e) {
35
                    preg_match('/\[\s\<\w+?>\s([\w]+)/s', $param->__toString(), $matches);
36
                    $this->type_hint = isset($matches[1]) ? $matches[1] : '';
37
                }
38
            }
39
        }
40
41
        $this->reference = $param->isPassedByReference();
42
        $this->name = $param->getName();
43
44
        if (KINT_PHP523) {
45
            $this->position = $param->getPosition();
46
        }
47
48
        if ($param->isDefaultValueAvailable()) {
49
            $default = $param->getDefaultValue();
50
            switch (gettype($default)) {
51
                case 'NULL':
52
                    $this->default = 'null';
53
                    break;
54
                case 'boolean':
55
                    $this->default = $default ? 'true' : 'false';
56
                    break;
57
                case 'array':
58
                    $this->default = count($default) ? 'array(...)' : 'array()';
59
                    break;
60
                default:
61
                    $this->default = var_export($default, true);
62
                    break;
63
            }
64
        }
65
    }
66
67
    public function getDefault()
68
    {
69
        return $this->default;
70
    }
71
}
72