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\Descriptor\Tag\VarDescriptor; |
19
|
|
|
use phpDocumentor\Reflection\Type; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Descriptor representing a property. |
23
|
|
|
*/ |
24
|
|
|
class PropertyDescriptor extends DescriptorAbstract implements Interfaces\PropertyInterface, Interfaces\VisibilityInterface |
25
|
|
|
{ |
26
|
|
|
/** @var ClassDescriptor|TraitDescriptor $parent */ |
27
|
|
|
protected $parent; |
28
|
|
|
|
29
|
|
|
/** @var string[]|null $types */ |
30
|
|
|
protected $types; |
31
|
|
|
|
32
|
|
|
/** @var string $default */ |
33
|
|
|
protected $default; |
34
|
|
|
|
35
|
|
|
/** @var bool $static */ |
36
|
|
|
protected $static = false; |
37
|
|
|
|
38
|
|
|
/** @var string $visibility */ |
39
|
|
|
protected $visibility = 'public'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param ClassDescriptor|TraitDescriptor $parent |
43
|
|
|
*/ |
44
|
2 |
|
public function setParent($parent) |
45
|
|
|
{ |
46
|
2 |
|
$this->setFullyQualifiedStructuralElementName( |
47
|
2 |
|
$parent->getFullyQualifiedStructuralElementName() . '::$' . $this->getName() |
48
|
|
|
); |
49
|
|
|
|
50
|
2 |
|
$this->parent = $parent; |
51
|
2 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return ClassDescriptor|TraitDescriptor |
55
|
|
|
*/ |
56
|
1 |
|
public function getParent() |
57
|
|
|
{ |
58
|
1 |
|
return $this->parent; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritDoc} |
63
|
|
|
*/ |
64
|
1 |
|
public function setDefault($default) |
65
|
|
|
{ |
66
|
1 |
|
$this->default = $default; |
67
|
1 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
1 |
|
public function getDefault() |
73
|
|
|
{ |
74
|
1 |
|
return $this->default; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritDoc} |
79
|
|
|
*/ |
80
|
1 |
|
public function setStatic($static) |
81
|
|
|
{ |
82
|
1 |
|
$this->static = $static; |
83
|
1 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritDoc} |
87
|
|
|
*/ |
88
|
1 |
|
public function isStatic() |
89
|
|
|
{ |
90
|
1 |
|
return $this->static; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritDoc} |
95
|
|
|
*/ |
96
|
1 |
|
public function setTypes(Type $types) |
97
|
|
|
{ |
98
|
1 |
|
$this->types = $types; |
|
|
|
|
99
|
1 |
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* {@inheritDoc} |
103
|
|
|
*/ |
104
|
2 |
|
public function getTypes() |
105
|
|
|
{ |
106
|
2 |
|
return [$this->getType()]; |
|
|
|
|
107
|
2 |
|
} |
108
|
|
|
|
109
|
|
|
public function getType() |
110
|
2 |
|
{ |
111
|
2 |
|
if ($this->types === null) { |
112
|
1 |
|
/** @var VarDescriptor $var */ |
113
|
|
|
$var = $this->getVar()->getIterator()->current(); |
114
|
|
|
if ($var) { |
115
|
|
|
return $var->getType(); |
116
|
2 |
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $this->types; |
120
|
|
|
} |
121
|
|
|
|
122
|
1 |
|
/** |
123
|
|
|
* {@inheritDoc} |
124
|
1 |
|
*/ |
125
|
1 |
|
public function setVisibility($visibility) |
126
|
|
|
{ |
127
|
|
|
$this->visibility = $visibility; |
128
|
|
|
} |
129
|
|
|
|
130
|
1 |
|
/** |
131
|
|
|
* {@inheritDoc} |
132
|
1 |
|
*/ |
133
|
|
|
public function getVisibility() |
134
|
|
|
{ |
135
|
|
|
return $this->visibility; |
136
|
|
|
} |
137
|
|
|
|
138
|
2 |
|
/** |
139
|
|
|
* @return Collection |
140
|
|
|
*/ |
141
|
2 |
|
public function getVar() |
142
|
2 |
|
{ |
143
|
1 |
|
/** @var Collection $var */ |
144
|
|
|
$var = $this->getTags()->get('var', new Collection()); |
145
|
|
|
if ($var->count() !== 0) { |
146
|
2 |
|
return $var; |
147
|
2 |
|
} |
148
|
1 |
|
|
149
|
|
|
$inheritedElement = $this->getInheritedElement(); |
150
|
|
|
if ($inheritedElement) { |
151
|
1 |
|
return $inheritedElement->getVar(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return new Collection(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Returns the file associated with the parent class or trait. |
159
|
1 |
|
* |
160
|
|
|
* @return FileDescriptor |
161
|
1 |
|
*/ |
162
|
|
|
public function getFile() |
163
|
|
|
{ |
164
|
|
|
return $this->getParent()->getFile(); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Returns the property from which this one should inherit, if any. |
169
|
2 |
|
* |
170
|
|
|
* @return PropertyDescriptor|null |
171
|
|
|
*/ |
172
|
2 |
|
public function getInheritedElement() |
173
|
|
|
{ |
174
|
2 |
|
/** @var ClassDescriptor|InterfaceDescriptor|null $associatedClass */ |
175
|
1 |
|
$associatedClass = $this->getParent(); |
176
|
2 |
|
|
177
|
|
|
if (($associatedClass instanceof ClassDescriptor || $associatedClass instanceof InterfaceDescriptor) |
178
|
|
|
&& ($associatedClass->getParent() instanceof ClassDescriptor |
179
|
|
|
|| $associatedClass->getParent() instanceof InterfaceDescriptor |
180
|
1 |
|
) |
181
|
|
|
) { |
182
|
1 |
|
/** @var ClassDescriptor|InterfaceDescriptor $parentClass */ |
183
|
|
|
$parentClass = $associatedClass->getParent(); |
184
|
|
|
|
185
|
1 |
|
return $parentClass->getProperties()->get($this->getName()); |
|
|
|
|
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return null; |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..