| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
namespace phpDocumentor\Reflection; |
| 15 |
|
| 16 |
use phpDocumentor\Reflection\DocBlock\Tag; |
| 17 |
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType; |
| 18 |
use Webmozart\Assert\Assert; |
| 19 |
|
| 20 |
final class DocBlock |
| 21 |
{ |
| 22 |
|
| 23 |
private string $summary; |
| 24 |
|
| 25 |
|
| 26 |
private DocBlock\Description $description; |
| 27 |
|
| 28 |
|
| 29 |
private array $tags = []; |
| 30 |
|
| 31 |
|
| 32 |
private ?Types\Context $context = null; |
| 33 |
|
| 34 |
|
| 35 |
private ?Location $location = null; |
| 36 |
|
| 37 |
|
| 38 |
private bool $isTemplateStart; |
| 39 |
|
| 40 |
|
| 41 |
private bool $isTemplateEnd; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public function __construct( |
| 49 |
string $summary = '', |
| 50 |
?DocBlock\Description $description = null, |
| 51 |
array $tags = [], |
| 52 |
?Types\Context $context = null, |
| 53 |
?Location $location = null, |
| 54 |
bool $isTemplateStart = false, |
| 55 |
bool $isTemplateEnd = false |
| 56 |
) { |
| 57 |
Assert::allIsInstanceOf($tags, Tag::class); |
| 58 |
|
| 59 |
$this->summary = $summary; |
| 60 |
$this->description = $description ?: new DocBlock\Description(''); |
| 61 |
foreach ($tags as $tag) { |
| 62 |
$this->addTag($tag); |
| 63 |
} |
| 64 |
|
| 65 |
$this->context = $context; |
| 66 |
$this->location = $location; |
| 67 |
|
| 68 |
$this->isTemplateEnd = $isTemplateEnd; |
| 69 |
$this->isTemplateStart = $isTemplateStart; |
| 70 |
} |
| 71 |
|
| 72 |
public function getSummary(): string |
| 73 |
{ |
| 74 |
return $this->summary; |
| 75 |
} |
| 76 |
|
| 77 |
public function getDescription(): DocBlock\Description |
| 78 |
{ |
| 79 |
return $this->description; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public function getContext(): ?Types\Context |
| 86 |
{ |
| 87 |
return $this->context; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public function getLocation(): ?Location |
| 94 |
{ |
| 95 |
return $this->location; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public function isTemplateStart(): bool |
| 118 |
{ |
| 119 |
return $this->isTemplateStart; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
public function isTemplateEnd(): bool |
| 128 |
{ |
| 129 |
return $this->isTemplateEnd; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public function getTags(): array |
| 138 |
{ |
| 139 |
return $this->tags; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
public function getTagsByName(string $name): array |
| 151 |
{ |
| 152 |
$result = []; |
| 153 |
|
| 154 |
foreach ($this->getTags() as $tag) { |
| 155 |
if ($tag->getName() !== $name) { |
| 156 |
continue; |
| 157 |
} |
| 158 |
|
| 159 |
$result[] = $tag; |
| 160 |
} |
| 161 |
|
| 162 |
return $result; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
public function getTagsWithTypeByName(string $name): array |
| 174 |
{ |
| 175 |
$result = []; |
| 176 |
|
| 177 |
foreach ($this->getTagsByName($name) as $tag) { |
| 178 |
if (!$tag instanceof TagWithType) { |
| 179 |
continue; |
| 180 |
} |
| 181 |
|
| 182 |
$result[] = $tag; |
| 183 |
} |
| 184 |
|
| 185 |
return $result; |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
public function hasTag(string $name): bool |
| 194 |
{ |
| 195 |
foreach ($this->getTags() as $tag) { |
| 196 |
if ($tag->getName() === $name) { |
| 197 |
return true; |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
return false; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
public function removeTag(Tag $tagToRemove): void |
| 210 |
{ |
| 211 |
foreach ($this->tags as $key => $tag) { |
| 212 |
if ($tag === $tagToRemove) { |
| 213 |
unset($this->tags[$key]); |
| 214 |
break; |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
private function addTag(Tag $tag): void |
| 225 |
{ |
| 226 |
$this->tags[] = $tag; |
| 227 |
} |
| 228 |
} |