44
55namespace TypeLang \PhpDocParser \DocBlock ;
66
7+ use TypeLang \Parser \Node \SerializableInterface ;
78use TypeLang \PhpDocParser \DocBlock \Tag \TagInterface ;
89
9- final class Description implements TagProviderInterface, \Stringable
10+ final class Description implements
11+ TagProviderInterface,
12+ SerializableInterface,
13+ \Stringable
1014{
1115 use TagProvider;
1216
1317 /**
1418 * @param iterable<array-key, TagInterface> $tags
1519 */
1620 public function __construct (
17- private readonly string $ bodyTemplate = '' ,
21+ private readonly string $ template = '' ,
1822 iterable $ tags = [],
1923 ) {
2024 $ this ->initializeTags ($ tags );
@@ -30,9 +34,40 @@ public static function create(string $body): self
3034 *
3135 * @psalm-immutable
3236 */
33- public function getBodyTemplate (): string
37+ public function getTemplate (): string
3438 {
35- return $ this ->bodyTemplate ;
39+ return $ this ->template ;
40+ }
41+
42+ /**
43+ * @return array{
44+ * template: string,
45+ * tags: list<array>
46+ * }
47+ */
48+ public function toArray (): array
49+ {
50+ $ tags = [];
51+
52+ foreach ($ this ->tags as $ tag ) {
53+ $ tags [] = $ tag ->toArray ();
54+ }
55+
56+ return [
57+ 'template ' => $ this ->template ,
58+ 'tags ' => $ tags ,
59+ ];
60+ }
61+
62+ /**
63+ * @return array{
64+ * template: string,
65+ * tags: list<array>
66+ * }
67+ */
68+ public function jsonSerialize (): array
69+ {
70+ return $ this ->toArray ();
3671 }
3772
3873 /**
@@ -41,6 +76,6 @@ public function getBodyTemplate(): string
4176 public function __toString (): string
4277 {
4378 /** @psalm-suppress ImplicitToStringCast */
44- return \vsprintf ($ this ->bodyTemplate , $ this ->tags );
79+ return \vsprintf ($ this ->template , $ this ->tags );
4580 }
4681}
0 commit comments