File tree Expand file tree Collapse file tree 7 files changed +34
-3
lines changed Expand file tree Collapse file tree 7 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 99 "issues" : " https://github.com/php-type-language/phpdoc/issues"
1010 },
1111 "require" : {
12- "php" : " ^8.1"
12+ "php" : " ^8.1" ,
13+ "ext-json" : " *"
1314 },
1415 "autoload" : {
1516 "psr-4" : {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ final class DocBlock implements
2121 OptionalDescriptionProviderInterface,
2222 TagsProviderInterface,
2323 \IteratorAggregate,
24+ \JsonSerializable,
2425 \ArrayAccess,
2526 \Countable
2627{
@@ -94,6 +95,14 @@ public function getIterator(): \Traversable
9495 return new \ArrayIterator ($ this ->tags );
9596 }
9697
98+ public function jsonSerialize (): array
99+ {
100+ return [
101+ 'description ' => $ this ->description ,
102+ 'tags ' => $ this ->tags ,
103+ ];
104+ }
105+
97106 /**
98107 * @return int<0, max>
99108 */
Original file line number Diff line number Diff line change @@ -37,6 +37,11 @@ public static function fromStringableOrNull(string|\Stringable|null $description
3737 return self ::fromStringable ($ description );
3838 }
3939
40+ public function jsonSerialize (): string
41+ {
42+ return $ this ->value ;
43+ }
44+
4045 public function __toString (): string
4146 {
4247 return $ this ->value ;
Original file line number Diff line number Diff line change 88 * Any class that implements this interface is a description object
99 * that can be represented as a raw string scalar value.
1010 */
11- interface DescriptionInterface extends \Stringable
11+ interface DescriptionInterface extends \JsonSerializable, \ Stringable
1212{
1313 /**
1414 * Returns a plain string representation of this description.
Original file line number Diff line number Diff line change @@ -88,6 +88,11 @@ public function offsetUnset(mixed $offset): void
8888 throw new \BadMethodCallException (static ::class . ' objects are immutable ' );
8989 }
9090
91+ public function jsonSerialize (): array
92+ {
93+ return $ this ->components ;
94+ }
95+
9196 public function __toString (): string
9297 {
9398 return \implode ('' , $ this ->components );
Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ public function getDescription(): ?DescriptionInterface
3131 return $ this ->description ;
3232 }
3333
34+ public function jsonSerialize (): array
35+ {
36+ return \array_filter ([
37+ 'name ' => $ this ->name ,
38+ 'description ' => $ this ->description ,
39+ ], static fn (mixed $ value ): bool => $ value !== null );
40+ }
41+
3442 public function __toString (): string
3543 {
3644 if ($ this ->description === null ) {
Original file line number Diff line number Diff line change 66
77use TypeLang \PHPDoc \Tag \Description \OptionalDescriptionProviderInterface ;
88
9- interface TagInterface extends OptionalDescriptionProviderInterface, \Stringable
9+ interface TagInterface extends
10+ OptionalDescriptionProviderInterface,
11+ \JsonSerializable,
12+ \Stringable
1013{
1114 /**
1215 * Returns the non-empty tag name string without the '@' prefix.
You can’t perform that action at this time.
0 commit comments