|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of phpDocumentor. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @copyright 2010-2015 Mike van Riel<[email protected]> |
|
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
|
11
|
|
|
* @link http://phpdoc.org |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace phpDocumentor\Reflection; |
|
15
|
|
|
|
|
16
|
|
|
use phpDocumentor\Reflection\DocBlock\Tag; |
|
17
|
|
|
use Webmozart\Assert\Assert; |
|
18
|
|
|
|
|
19
|
|
|
final class DocBlock |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var string The opening line for this docblock. */ |
|
22
|
|
|
private $summary = ''; |
|
23
|
|
|
|
|
24
|
|
|
/** @var DocBlock\Description The actual description for this docblock. */ |
|
25
|
|
|
private $description = null; |
|
26
|
|
|
|
|
27
|
|
|
/** @var Tag[] An array containing all the tags in this docblock; except inline. */ |
|
28
|
|
|
private $tags = []; |
|
29
|
|
|
|
|
30
|
|
|
/** @var Types\Context Information about the context of this DocBlock. */ |
|
31
|
|
|
private $context = null; |
|
32
|
|
|
|
|
33
|
|
|
/** @var Location Information about the location of this DocBlock. */ |
|
34
|
|
|
private $location = null; |
|
35
|
|
|
|
|
36
|
|
|
/** @var bool Is this DocBlock (the start of) a template? */ |
|
37
|
|
|
private $isTemplateStart = false; |
|
38
|
|
|
|
|
39
|
|
|
/** @var bool Does this DocBlock signify the end of a DocBlock template? */ |
|
40
|
|
|
private $isTemplateEnd = false; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param DocBlock\Tag[] $tags |
|
44
|
|
|
* @param Types\Context $context The context in which the DocBlock occurs. |
|
45
|
|
|
* @param Location $location The location within the file that this DocBlock occurs in. |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct( |
|
48
|
|
|
string $summary = '', |
|
49
|
|
|
?DocBlock\Description $description = null, |
|
50
|
16 |
|
array $tags = [], |
|
51
|
|
|
?Types\Context $context = null, |
|
52
|
|
|
?Location $location = null, |
|
53
|
|
|
bool $isTemplateStart = false, |
|
54
|
|
|
bool $isTemplateEnd = false |
|
55
|
|
|
) { |
|
56
|
|
|
Assert::allIsInstanceOf($tags, Tag::class); |
|
57
|
|
|
|
|
58
|
|
|
$this->summary = $summary; |
|
59
|
16 |
|
$this->description = $description ?: new DocBlock\Description(''); |
|
60
|
15 |
|
foreach ($tags as $tag) { |
|
61
|
14 |
|
$this->addTag($tag); |
|
62
|
13 |
|
} |
|
63
|
|
|
|
|
64
|
12 |
|
$this->context = $context; |
|
65
|
12 |
|
$this->location = $location; |
|
66
|
12 |
|
|
|
67
|
4 |
|
$this->isTemplateEnd = $isTemplateEnd; |
|
68
|
|
|
$this->isTemplateStart = $isTemplateStart; |
|
69
|
|
|
} |
|
70
|
12 |
|
|
|
71
|
12 |
|
public function getSummary(): string |
|
72
|
|
|
{ |
|
73
|
12 |
|
return $this->summary; |
|
74
|
12 |
|
} |
|
75
|
12 |
|
|
|
76
|
|
|
public function getDescription(): DocBlock\Description |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->description; |
|
79
|
|
|
} |
|
80
|
1 |
|
|
|
81
|
|
|
/** |
|
82
|
1 |
|
* Returns the current context. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getContext(): Types\Context |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->context; |
|
87
|
|
|
} |
|
88
|
1 |
|
|
|
89
|
|
|
/** |
|
90
|
1 |
|
* Returns the current location. |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getLocation(): ?Location |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->location; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
1 |
|
* Returns whether this DocBlock is the start of a Template section. |
|
99
|
|
|
* |
|
100
|
1 |
|
* A Docblock may serve as template for a series of subsequent DocBlocks. This is indicated by a special marker |
|
101
|
|
|
* (`#@+`) that is appended directly after the opening `/**` of a DocBlock. |
|
102
|
|
|
* |
|
103
|
|
|
* An example of such an opening is: |
|
104
|
|
|
* |
|
105
|
|
|
* ``` |
|
106
|
|
|
* /**#@+ |
|
107
|
|
|
* * My DocBlock |
|
108
|
1 |
|
* * / |
|
109
|
|
|
* ``` |
|
110
|
1 |
|
* |
|
111
|
|
|
* The description and tags (not the summary!) are copied onto all subsequent DocBlocks and also applied to all |
|
112
|
|
|
* elements that follow until another DocBlock is found that contains the closing marker (`#@-`). |
|
113
|
|
|
* |
|
114
|
|
|
* @see self::isTemplateEnd() for the check whether a closing marker was provided. |
|
115
|
|
|
*/ |
|
116
|
|
|
public function isTemplateStart(): bool |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->isTemplateStart; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Returns whether this DocBlock is the end of a Template section. |
|
123
|
|
|
* |
|
124
|
|
|
* @see self::isTemplateStart() for a more complete description of the Docblock Template functionality. |
|
125
|
|
|
*/ |
|
126
|
|
|
public function isTemplateEnd(): bool |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->isTemplateEnd; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Returns the tags for this DocBlock. |
|
133
|
|
|
* |
|
134
|
1 |
|
* @return Tag[] |
|
135
|
|
|
*/ |
|
136
|
1 |
|
public function getTags() |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->tags; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Returns an array of tags matching the given name. If no tags are found |
|
143
|
|
|
* an empty array is returned. |
|
144
|
|
|
* |
|
145
|
|
|
* @param string $name String to search by. |
|
146
|
1 |
|
* |
|
147
|
|
|
* @return Tag[] |
|
148
|
1 |
|
*/ |
|
149
|
|
|
public function getTagsByName(string $name) |
|
150
|
|
|
{ |
|
151
|
|
|
$result = []; |
|
152
|
|
|
|
|
153
|
|
|
/** @var Tag $tag */ |
|
154
|
|
|
foreach ($this->getTags() as $tag) { |
|
155
|
|
|
if ($tag->getName() !== $name) { |
|
156
|
1 |
|
continue; |
|
157
|
|
|
} |
|
158
|
1 |
|
|
|
159
|
|
|
$result[] = $tag; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return $result; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Checks if a tag of a certain type is present in this DocBlock. |
|
167
|
|
|
* |
|
168
|
|
|
* @param string $name Tag name to check for. |
|
169
|
2 |
|
*/ |
|
170
|
|
|
public function hasTag(string $name): bool |
|
171
|
2 |
|
{ |
|
172
|
|
|
/** @var Tag $tag */ |
|
173
|
1 |
|
foreach ($this->getTags() as $tag) { |
|
174
|
|
|
if ($tag->getName() === $name) { |
|
175
|
|
|
return true; |
|
176
|
1 |
|
} |
|
177
|
1 |
|
} |
|
178
|
1 |
|
|
|
179
|
|
|
return false; |
|
180
|
|
|
} |
|
181
|
1 |
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Remove a tag from this DocBlock. |
|
184
|
1 |
|
* |
|
185
|
|
|
* @param Tag $tag The tag to remove. |
|
|
|
|
|
|
186
|
|
|
*/ |
|
187
|
|
|
public function removeTag(Tag $tagToRemove): void |
|
188
|
|
|
{ |
|
189
|
|
|
foreach ($this->tags as $key => $tag) { |
|
190
|
|
|
if ($tag === $tagToRemove) { |
|
191
|
|
|
unset($this->tags[$key]); |
|
192
|
|
|
break; |
|
193
|
|
|
} |
|
194
|
2 |
|
} |
|
195
|
|
|
} |
|
196
|
2 |
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Adds a tag to this DocBlock. |
|
199
|
1 |
|
* |
|
200
|
1 |
|
* @param Tag $tag The tag to add. |
|
201
|
1 |
|
*/ |
|
202
|
|
|
private function addTag(Tag $tag): void |
|
203
|
|
|
{ |
|
204
|
|
|
$this->tags[] = $tag; |
|
205
|
1 |
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.