|
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
|
1 |
|
public function setMethod(MethodDescriptor $method) |
|
44
|
|
|
{ |
|
45
|
1 |
|
$this->method = $method; |
|
46
|
1 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getMethod(): ?MethodDescriptor |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->method; |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
/** |
|
54
|
1 |
|
* {@inheritDoc} |
|
55
|
|
|
*/ |
|
56
|
|
|
public function setType(?Type $type) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->type = $type; |
|
59
|
2 |
|
} |
|
60
|
|
|
|
|
61
|
2 |
|
/** |
|
62
|
1 |
|
* {@inheritDoc} |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getType(): ?Type |
|
65
|
2 |
|
{ |
|
66
|
|
|
if ($this->type === null && $this->getInheritedElement() !== null) { |
|
67
|
|
|
$this->setType($this->getInheritedElement()->getType()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
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
|
1 |
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
/** |
|
80
|
1 |
|
* @return null|ArgumentDescriptor |
|
81
|
1 |
|
*/ |
|
82
|
1 |
|
public function getInheritedElement() |
|
83
|
1 |
|
{ |
|
84
|
1 |
|
if ($this->method instanceof MethodDescriptor && |
|
85
|
|
|
$this->method->getInheritedElement() instanceof MethodDescriptor) { |
|
86
|
|
|
$parents = $this->method->getInheritedElement()->getArguments(); |
|
87
|
|
|
foreach ($parents as $parentArgument) { |
|
88
|
|
|
if ($parentArgument->getName() === $this->getName()) { |
|
89
|
1 |
|
return $parentArgument; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return null; |
|
95
|
1 |
|
} |
|
96
|
|
|
|
|
97
|
1 |
|
/** |
|
98
|
1 |
|
* {@inheritDoc} |
|
99
|
|
|
*/ |
|
100
|
|
|
public function setDefault($value) |
|
101
|
|
|
{ |
|
102
|
|
|
$this->default = $value; |
|
103
|
1 |
|
} |
|
104
|
|
|
|
|
105
|
1 |
|
/** |
|
106
|
|
|
* {@inheritDoc} |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getDefault() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->default; |
|
111
|
1 |
|
} |
|
112
|
|
|
|
|
113
|
1 |
|
/** |
|
114
|
1 |
|
* {@inheritDoc} |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setByReference($byReference) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->byReference = $byReference; |
|
119
|
1 |
|
} |
|
120
|
|
|
|
|
121
|
1 |
|
/** |
|
122
|
|
|
* {@inheritDoc} |
|
123
|
|
|
*/ |
|
124
|
|
|
public function isByReference() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->byReference; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Sets whether this argument represents a variadic argument. |
|
131
|
1 |
|
* |
|
132
|
|
|
* @param boolean $isVariadic |
|
133
|
1 |
|
* |
|
134
|
1 |
|
* @return false |
|
135
|
|
|
*/ |
|
136
|
|
|
public function setVariadic($isVariadic) |
|
137
|
|
|
{ |
|
138
|
|
|
$this->isVariadic = $isVariadic; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
1 |
|
/** |
|
142
|
|
|
* Returns whether this argument represents a variadic argument. |
|
143
|
1 |
|
* |
|
144
|
|
|
* @return boolean |
|
145
|
|
|
*/ |
|
146
|
|
|
public function isVariadic() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->isVariadic; |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|