1 | <?php |
||
18 | final class DocBlock |
||
19 | { |
||
20 | /** @var string The opening line for this docblock. */ |
||
21 | private $summary = ''; |
||
22 | |||
23 | /** @var DocBlock\Description The actual description for this docblock. */ |
||
24 | private $description = null; |
||
25 | |||
26 | /** @var Tag[] An array containing all the tags in this docblock; except inline. */ |
||
27 | private $tags = array(); |
||
28 | |||
29 | /** @var Types\Context Information about the context of this DocBlock. */ |
||
30 | private $context = null; |
||
31 | |||
32 | /** @var Location Information about the location of this DocBlock. */ |
||
33 | private $location = null; |
||
34 | |||
35 | /** @var bool Is this DocBlock (the start of) a template? */ |
||
36 | private $isTemplateStart = false; |
||
37 | |||
38 | /** @var bool Does this DocBlock signify the end of a DocBlock template? */ |
||
39 | private $isTemplateEnd = false; |
||
40 | |||
41 | /** |
||
42 | * @param string $summary |
||
43 | * @param DocBlock\Description $description |
||
44 | * @param DocBlock\Tag[] $tags |
||
45 | * @param Types\Context $context The context in which the DocBlock occurs. |
||
46 | * @param Location $location The location within the file that this DocBlock occurs in. |
||
47 | * @param bool $isTemplateStart |
||
48 | * @param bool $isTemplateEnd |
||
49 | */ |
||
50 | 15 | public function __construct( |
|
51 | $summary = '', |
||
52 | DocBlock\Description $description = null, |
||
53 | array $tags = [], |
||
54 | Types\Context $context = null, |
||
55 | Location $location = null, |
||
56 | $isTemplateStart = false, |
||
57 | $isTemplateEnd = false |
||
58 | ) |
||
59 | { |
||
|
|||
60 | 15 | Assert::string($summary); |
|
61 | 14 | Assert::boolean($isTemplateStart); |
|
62 | 13 | Assert::boolean($isTemplateEnd); |
|
63 | 12 | Assert::allIsInstanceOf($tags, Tag::class); |
|
64 | |||
65 | 11 | $this->summary = $summary; |
|
66 | 11 | $this->description = $description ?: new DocBlock\Description(''); |
|
67 | 11 | foreach ($tags as $tag) { |
|
68 | 3 | $this->addTag($tag); |
|
69 | } |
||
70 | |||
71 | 11 | $this->context = $context; |
|
72 | 11 | $this->location = $location; |
|
73 | |||
74 | 11 | $this->isTemplateEnd = $isTemplateEnd; |
|
75 | 11 | $this->isTemplateStart = $isTemplateStart; |
|
76 | 11 | } |
|
77 | |||
78 | /** |
||
79 | * @return string |
||
80 | */ |
||
81 | 1 | public function getSummary() |
|
85 | |||
86 | /** |
||
87 | * @return DocBlock\Description |
||
88 | */ |
||
89 | 1 | public function getDescription() |
|
93 | |||
94 | /** |
||
95 | * Returns the current context. |
||
96 | * |
||
97 | * @return Types\Context |
||
98 | */ |
||
99 | 1 | public function getContext() |
|
103 | |||
104 | /** |
||
105 | * Returns the current location. |
||
106 | * |
||
107 | * @return Location |
||
108 | */ |
||
109 | 1 | public function getLocation() |
|
113 | |||
114 | /** |
||
115 | * Returns whether this DocBlock is the start of a Template section. |
||
116 | * |
||
117 | * A Docblock may serve as template for a series of subsequent DocBlocks. This is indicated by a special marker |
||
118 | * (`#@+`) that is appended directly after the opening `/**` of a DocBlock. |
||
119 | * |
||
120 | * An example of such an opening is: |
||
121 | * |
||
122 | * ``` |
||
123 | * /**#@+ |
||
124 | * * My DocBlock |
||
125 | * * / |
||
126 | * ``` |
||
127 | * |
||
128 | * The description and tags (not the summary!) are copied onto all subsequent DocBlocks and also applied to all |
||
129 | * elements that follow until another DocBlock is found that contains the closing marker (`#@-`). |
||
130 | * |
||
131 | * @see self::isTemplateEnd() for the check whether a closing marker was provided. |
||
132 | * |
||
133 | * @return boolean |
||
134 | */ |
||
135 | 1 | public function isTemplateStart() |
|
139 | |||
140 | /** |
||
141 | * Returns whether this DocBlock is the end of a Template section. |
||
142 | * |
||
143 | * @see self::isTemplateStart() for a more complete description of the Docblock Template functionality. |
||
144 | * |
||
145 | * @return boolean |
||
146 | */ |
||
147 | 1 | public function isTemplateEnd() |
|
151 | |||
152 | /** |
||
153 | * Returns the tags for this DocBlock. |
||
154 | * |
||
155 | * @return Tag[] |
||
156 | */ |
||
157 | 1 | public function getTags() |
|
161 | |||
162 | /** |
||
163 | * Returns an array of tags matching the given name. If no tags are found |
||
164 | * an empty array is returned. |
||
165 | * |
||
166 | * @param string $name String to search by. |
||
167 | * |
||
168 | * @return Tag[] |
||
169 | */ |
||
170 | 2 | public function getTagsByName($name) |
|
187 | |||
188 | /** |
||
189 | * Checks if a tag of a certain type is present in this DocBlock. |
||
190 | * |
||
191 | * @param string $name Tag name to check for. |
||
192 | * |
||
193 | * @return bool |
||
194 | */ |
||
195 | 2 | public function hasTag($name) |
|
208 | |||
209 | /** |
||
210 | * Remove a tag from this DocBlock. |
||
211 | * |
||
212 | * @param Tag $tag The tag to remove. |
||
213 | * |
||
214 | * @return void |
||
215 | */ |
||
216 | public function removeTag(Tag $tagToRemove) |
||
225 | |||
226 | /** |
||
227 | * Adds a tag to this DocBlock. |
||
228 | * |
||
229 | * @param Tag $tag The tag to add. |
||
230 | * |
||
231 | * @return void |
||
232 | */ |
||
233 | 3 | private function addTag(Tag $tag) |
|
237 | } |
||
238 |