55namespace TypeLang \PHPDoc ;
66
77use TypeLang \PHPDoc \Tag \Description ;
8- use TypeLang \PHPDoc \Tag \Tag ;
8+ use TypeLang \PHPDoc \Tag \DescriptionInterface ;
9+ use TypeLang \PHPDoc \Tag \DescriptionProviderInterface ;
10+ use TypeLang \PHPDoc \Tag \TagInterface ;
911use TypeLang \PHPDoc \Tag \TagProvider ;
1012use TypeLang \PHPDoc \Tag \TagProviderInterface ;
1113
1214/**
13- * @template-implements \IteratorAggregate<int<0, max>, Tag>
14- * @template-implements \ArrayAccess<int<0, max>, Tag|null>
15+ * This class represents structure containing a description and a set of tags
16+ * that describe an arbitrary DocBlock Comment in the code.
17+ *
18+ * @template-implements \IteratorAggregate<int<0, max>, TagInterface>
19+ * @template-implements \ArrayAccess<int<0, max>, TagInterface|null>
1520 */
1621final class DocBlock implements
22+ DescriptionProviderInterface,
1723 TagProviderInterface,
1824 \IteratorAggregate,
1925 \ArrayAccess
2026{
2127 use TagProvider;
2228
29+ private readonly DescriptionInterface $ description ;
30+
2331 /**
24- * @param iterable<array-key, Tag> $tags
32+ * @param iterable<array-key, TagInterface> $tags List of all tags contained in
33+ * a docblock object.
34+ *
35+ * Note that the constructor can receive an arbitrary iterator, like
36+ * {@see \Traversable} or {@see array}, but the object itself
37+ * contains the directly generated list ({@see array}} of
38+ * {@see TagInterface} objects.
2539 */
2640 public function __construct (
27- private readonly Description $ description = new Description () ,
41+ string | \ Stringable $ description = '' ,
2842 iterable $ tags = [],
2943 ) {
44+ $ this ->description = Description::fromStringable ($ description );
45+
3046 $ this ->bootTagProvider ($ tags );
3147 }
3248
@@ -35,7 +51,7 @@ public function offsetExists(mixed $offset): bool
3551 return isset ($ this ->tags [$ offset ]);
3652 }
3753
38- public function offsetGet (mixed $ offset ): ?Tag
54+ public function offsetGet (mixed $ offset ): ?TagInterface
3955 {
4056 return $ this ->tags [$ offset ] ?? null ;
4157 }
@@ -50,7 +66,7 @@ public function offsetUnset(mixed $offset): void
5066 throw new \BadMethodCallException (self ::class . ' objects are immutable ' );
5167 }
5268
53- public function getDescription (): Description
69+ public function getDescription (): DescriptionInterface
5470 {
5571 return $ this ->description ;
5672 }
0 commit comments