Completed
Push — master ( f1462e...556a60 )
by Nikola
09:28 queued 07:57
created

ParameterMetadata::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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
     * ParameterMetadata constructor.
48
     *
49
     * @param string $name
50
     * @param string $type
51
     * @param bool $byRef
52
     * @param bool $variadic
53
     * @param mixed $default
54
     */
55
    public function __construct($name, $type = null, $byRef = false, $variadic = false, $default = null)
56
    {
57
        $this->name = $name;
58
        $this->type = $type;
59
        $this->byRef = $byRef;
60
        $this->variadic = $variadic;
61
        $this->default = $default;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getName()
68
    {
69
        return $this->name;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getType()
76
    {
77
        return $this->type;
78
    }
79
80
    /**
81
     * @return bool
82
     */
83
    public function byReference()
84
    {
85
        return $this->byRef;
86
    }
87
88
    /**
89
     * @return bool
90
     */
91
    public function isVariadic()
92
    {
93
        return $this->variadic;
94
    }
95
96
    /**
97
     * @return mixed
98
     */
99
    public function getDefault()
100
    {
101
        return $this->default;
102
    }
103
104
    /**
105
     * Creates parameter metadata instance from \PhpParser\Node\Param
106
     *
107
     * @param Param $param
108
     * @return ParameterMetadata|static
109
     */
110
    public static function fromParameter(Param $param)
111
    {
112
        return new static(
113
            $param->name,
114
            $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...
115
            $param->byRef,
116
            $param->variadic,
117
            $param->default
118
        );
119
    }
120
}
121