ParameterMetadata   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 117
ccs 8
cts 28
cp 0.2857
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getName() 0 4 1
A getType() 0 4 1
A byReference() 0 4 1
A isVariadic() 0 4 1
A getDefault() 0 4 1
A getAst() 0 4 1
A fromParameter() 0 11 1
1
<?php
2
/*
3
 * This file is part of the Abstract builder package, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\AbstractBuilder\Ast\Metadata;
11
12
use PhpParser\Node\Param;
13
14
/**
15
 * Class ParameterMetadata
16
 *
17
 * @package RunOpenCode\AbstractBuilder\Ast\Metadata
18
 */
19
class ParameterMetadata
20
{
21
    /**
22
     * @var string
23
     */
24
    private $name;
25
26
    /**
27
     * @var string
28
     */
29
    private $type;
30
31
    /**
32
     * @var bool
33
     */
34
    private $byRef;
35
36
    /**
37
     * @var bool
38
     */
39
    private $variadic;
40
41
    /**
42
     * @var mixed
43
     */
44
    private $default;
45
46
    /**
47
     * @var Param
48
     */
49
    private $ast;
50
51
    /**
52
     * ParameterMetadata constructor.
53
     *
54
     * @param string $name
55
     * @param string $type
56
     * @param bool $byRef
57
     * @param bool $variadic
58
     * @param mixed $default
59
     */
60 1
    public function __construct($name, $type = null, $byRef = false, $variadic = false, $default = null, Param $ast = null)
61
    {
62 1
        $this->name = $name;
63 1
        $this->type = $type;
64 1
        $this->byRef = $byRef;
65 1
        $this->variadic = $variadic;
66 1
        $this->default = $default;
67 1
        $this->ast = $ast;
68 1
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getName()
74
    {
75
        return $this->name;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getType()
82
    {
83
        return $this->type;
84
    }
85
86
    /**
87
     * @return bool
88
     */
89
    public function byReference()
90
    {
91
        return $this->byRef;
92
    }
93
94
    /**
95
     * @return bool
96
     */
97
    public function isVariadic()
98
    {
99
        return $this->variadic;
100
    }
101
102
    /**
103
     * @return mixed
104
     */
105
    public function getDefault()
106
    {
107
        return $this->default;
108
    }
109
110
    /**
111
     * @return Param
112
     */
113
    public function getAst()
114
    {
115
        return $this->ast;
116
    }
117
118
    /**
119
     * Creates parameter metadata instance from \PhpParser\Node\Param
120
     *
121
     * @param Param $param
122
     * @return ParameterMetadata|static
123
     */
124
    public static function fromParameter(Param $param)
125
    {
126
        return new static(
127
            $param->name,
128
            $param->type,
0 ignored issues
show
Bug introduced by
It seems like $param->type can also be of type object<PhpParser\Node\Name> or object<PhpParser\Node\NullableType>; however, RunOpenCode\AbstractBuil...Metadata::__construct() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
129
            $param->byRef,
130
            $param->variadic,
131
            $param->default,
132
            $param
133
        );
134
    }
135
}
136