1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of phpDocumentor. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @author Mike van Riel <[email protected]> |
11
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
13
|
|
|
* @link http://phpdoc.org |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace phpDocumentor\Descriptor; |
17
|
|
|
|
18
|
|
|
use phpDocumentor\Reflection\Type; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Descriptor representing a single Argument of a method or function. |
22
|
|
|
*/ |
23
|
|
|
class ArgumentDescriptor extends DescriptorAbstract implements Interfaces\ArgumentInterface |
24
|
|
|
{ |
25
|
|
|
/** @var MethodDescriptor $method */ |
26
|
|
|
protected $method; |
27
|
|
|
|
28
|
|
|
/** @var Type|null $type normalized type of this argument */ |
29
|
|
|
protected $type = null; |
30
|
|
|
|
31
|
|
|
/** @var string|null $default the default value for an argument or null if none is provided */ |
32
|
|
|
protected $default; |
33
|
|
|
|
34
|
|
|
/** @var bool $byReference whether the argument passes the parameter by reference instead of by value */ |
35
|
|
|
protected $byReference = false; |
36
|
|
|
|
37
|
|
|
/** @var boolean Determines if this Argument represents a variadic argument */ |
38
|
|
|
protected $isVariadic = false; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* To which method does this argument belong to |
42
|
|
|
*/ |
43
|
2 |
|
public function setMethod(MethodDescriptor $method) |
44
|
|
|
{ |
45
|
2 |
|
$this->method = $method; |
46
|
2 |
|
} |
47
|
|
|
|
48
|
1 |
|
public function getMethod(): ?MethodDescriptor |
49
|
|
|
{ |
50
|
1 |
|
return $this->method; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritDoc} |
55
|
|
|
*/ |
56
|
1 |
|
public function setType(?Type $type) |
57
|
|
|
{ |
58
|
1 |
|
$this->type = $type; |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritDoc} |
63
|
|
|
*/ |
64
|
2 |
|
public function getType(): ?Type |
65
|
|
|
{ |
66
|
2 |
|
if ($this->type === null && $this->getInheritedElement() !== null) { |
67
|
1 |
|
$this->setType($this->getInheritedElement()->getType()); |
68
|
|
|
} |
69
|
|
|
|
70
|
2 |
|
return $this->type; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getTypes(): array |
74
|
|
|
{ |
75
|
|
|
trigger_error('Please use getType', E_USER_DEPRECATED); |
76
|
|
|
return [$this->getType()]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return null|ArgumentDescriptor |
81
|
|
|
*/ |
82
|
1 |
|
public function getInheritedElement() |
83
|
|
|
{ |
84
|
1 |
|
if ($this->method instanceof MethodDescriptor && |
85
|
1 |
|
$this->method->getInheritedElement() instanceof MethodDescriptor) { |
86
|
1 |
|
$parents = $this->method->getInheritedElement()->getArguments(); |
87
|
1 |
|
foreach ($parents as $parentArgument) { |
88
|
1 |
|
if ($parentArgument->getName() === $this->getName()) { |
89
|
1 |
|
return $parentArgument; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
1 |
|
return null; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritDoc} |
99
|
|
|
*/ |
100
|
1 |
|
public function setDefault($value) |
101
|
|
|
{ |
102
|
1 |
|
$this->default = $value; |
103
|
1 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritDoc} |
107
|
|
|
*/ |
108
|
1 |
|
public function getDefault() |
109
|
|
|
{ |
110
|
1 |
|
return $this->default; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritDoc} |
115
|
|
|
*/ |
116
|
1 |
|
public function setByReference($byReference) |
117
|
|
|
{ |
118
|
1 |
|
$this->byReference = $byReference; |
119
|
1 |
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* {@inheritDoc} |
123
|
|
|
*/ |
124
|
1 |
|
public function isByReference() |
125
|
|
|
{ |
126
|
1 |
|
return $this->byReference; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Sets whether this argument represents a variadic argument. |
131
|
|
|
* |
132
|
|
|
* @param boolean $isVariadic |
133
|
|
|
* |
134
|
|
|
* @return false |
135
|
|
|
*/ |
136
|
1 |
|
public function setVariadic($isVariadic) |
137
|
|
|
{ |
138
|
1 |
|
$this->isVariadic = $isVariadic; |
139
|
1 |
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Returns whether this argument represents a variadic argument. |
143
|
|
|
* |
144
|
|
|
* @return boolean |
145
|
|
|
*/ |
146
|
1 |
|
public function isVariadic() |
147
|
|
|
{ |
148
|
1 |
|
return $this->isVariadic; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|