Skip to content

Commit a5cab59

Browse files
author
Kirill Nesmeyanov
committed
Improve tag representation
1 parent aaa5a53 commit a5cab59

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/DocBlock/Tag/Tag.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,9 @@ public function getDescription(): Description|null
4646
*/
4747
public function __toString(): string
4848
{
49-
if ($this->description === null) {
50-
return \sprintf('@%s', $this->name);
51-
}
52-
53-
return \vsprintf('@%s %s', [
49+
return \rtrim(\vsprintf('@%s %s', [
5450
$this->name,
5551
(string)$this->description,
56-
]);
52+
]));
5753
}
5854
}

src/DocBlock/Tag/TypedTag.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,18 @@ public function getType(): TypeStatement
2323
{
2424
return $this->type;
2525
}
26+
27+
/**
28+
* @psalm-immutable
29+
*/
30+
public function __toString(): string
31+
{
32+
return \rtrim(\vsprintf('@%s %s %s', [
33+
$this->name,
34+
\property_exists($this->type, 'name')
35+
? (string)$this->type->name
36+
: $this->type::class,
37+
(string)$this->description,
38+
]));
39+
}
2640
}

0 commit comments

Comments
 (0)