5
5
namespace TypeLang \PHPDoc ;
6
6
7
7
use 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 ;
9
11
use TypeLang \PHPDoc \Tag \TagProvider ;
10
12
use TypeLang \PHPDoc \Tag \TagProviderInterface ;
11
13
12
14
/**
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>
15
20
*/
16
21
final class DocBlock implements
22
+ DescriptionProviderInterface,
17
23
TagProviderInterface,
18
24
\IteratorAggregate,
19
25
\ArrayAccess
20
26
{
21
27
use TagProvider;
22
28
29
+ private readonly DescriptionInterface $ description ;
30
+
23
31
/**
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.
25
39
*/
26
40
public function __construct (
27
- private readonly Description $ description = new Description () ,
41
+ string | \ Stringable $ description = '' ,
28
42
iterable $ tags = [],
29
43
) {
44
+ $ this ->description = Description::fromStringable ($ description );
45
+
30
46
$ this ->bootTagProvider ($ tags );
31
47
}
32
48
@@ -35,7 +51,7 @@ public function offsetExists(mixed $offset): bool
35
51
return isset ($ this ->tags [$ offset ]);
36
52
}
37
53
38
- public function offsetGet (mixed $ offset ): ?Tag
54
+ public function offsetGet (mixed $ offset ): ?TagInterface
39
55
{
40
56
return $ this ->tags [$ offset ] ?? null ;
41
57
}
@@ -50,7 +66,7 @@ public function offsetUnset(mixed $offset): void
50
66
throw new \BadMethodCallException (self ::class . ' objects are immutable ' );
51
67
}
52
68
53
- public function getDescription (): Description
69
+ public function getDescription (): DescriptionInterface
54
70
{
55
71
return $ this ->description ;
56
72
}
0 commit comments