-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDocBlock.php
More file actions
99 lines (87 loc) · 2.76 KB
/
Copy pathDocBlock.php
File metadata and controls
99 lines (87 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
declare(strict_types=1);
namespace TypeLang\PHPDoc\DocBlock;
use TypeLang\PHPDoc\DocBlock\Description\Description;
use TypeLang\PHPDoc\DocBlock\Description\DescriptionInterface;
use TypeLang\PHPDoc\DocBlock\Description\OptionalDescriptionProviderInterface;
use TypeLang\PHPDoc\DocBlock\Tag\TagInterface;
use TypeLang\PHPDoc\DocBlock\Tag\TagsProviderInterface;
/**
* An implementation represents structure containing a description and a set
* of tags that describe an arbitrary DocBlock Comment in the code.
*
* @template-implements \ArrayAccess<array-key, TagInterface|null>
* @template-implements \IteratorAggregate<array-key, TagInterface>
*/
final class DocBlock implements
OptionalDescriptionProviderInterface,
TagsProviderInterface,
\IteratorAggregate,
\ArrayAccess,
\Countable
{
public readonly ?DescriptionInterface $description;
/**
* @var list<TagInterface>
*/
public readonly array $tags;
/**
* @param iterable<array-key, TagInterface> $tags List of all tags contained in
* a docblock object.
*
* Note that the constructor can receive an arbitrary iterator, like
* {@see \Traversable} or {@see array}, but the object itself
* contains the directly generated list ({@see array}} of
* {@see TagInterface} objects.
*/
public function __construct(
string|\Stringable $description = '',
iterable $tags = [],
) {
$this->description = Description::fromStringable($description);
$this->tags = \array_values([...$tags]);
}
/**
* @internal direct usage of {@see offsetExists()} is not recommended
*/
public function offsetExists(mixed $offset): bool
{
return isset($this->tags[$offset]);
}
/**
* @internal direct usage of {@see offsetGet()} is not recommended
*/
public function offsetGet(mixed $offset): ?TagInterface
{
return $this->tags[$offset] ?? null;
}
/**
* @internal direct usage of {@see offsetSet()} is not recommended
*
* @throws \BadMethodCallException
*/
public function offsetSet(mixed $offset, mixed $value): void
{
throw new \BadMethodCallException(self::class . ' objects are immutable');
}
/**
* @internal direct usage of {@see offsetUnset()} is not recommended
*
* @throws \BadMethodCallException
*/
public function offsetUnset(mixed $offset): void
{
throw new \BadMethodCallException(self::class . ' objects are immutable');
}
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->tags);
}
/**
* @return int<0, max>
*/
public function count(): int
{
return \count($this->tags);
}
}