|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace TypeLang\PhpDocParser\DocBlock\Tag; |
| 6 | + |
| 7 | +use TypeLang\Parser\Node\Stmt\TypeStatement; |
| 8 | + |
| 9 | +final class TemplateTag extends Tag implements OptionalTypeProviderInterface |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @param non-empty-string $typeName |
| 13 | + * @param TypeStatement|null $type |
| 14 | + * @param \Stringable|string|null $description |
| 15 | + */ |
| 16 | + public function __construct( |
| 17 | + private readonly string $typeName, |
| 18 | + private readonly ?TypeStatement $type = null, |
| 19 | + \Stringable|string|null $description = null |
| 20 | + ) { |
| 21 | + parent::__construct('template', $description); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * @return non-empty-string |
| 26 | + */ |
| 27 | + public function getTypeName(): string |
| 28 | + { |
| 29 | + return $this->typeName; |
| 30 | + } |
| 31 | + |
| 32 | + public function getType(): ?TypeStatement |
| 33 | + { |
| 34 | + return $this->type; |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @psalm-immutable |
| 39 | + */ |
| 40 | + public function __toString(): string |
| 41 | + { |
| 42 | + if ($this->type === null) { |
| 43 | + return \rtrim(\vsprintf('@%s %s %s', [ |
| 44 | + $this->name, |
| 45 | + $this->typeName, |
| 46 | + (string)$this->description, |
| 47 | + ])); |
| 48 | + } |
| 49 | + |
| 50 | + return \rtrim(\vsprintf('@%s %s of %s %s', [ |
| 51 | + $this->name, |
| 52 | + $this->typeName, |
| 53 | + TypedTag::getTypeAsString($this->type), |
| 54 | + (string)$this->description, |
| 55 | + ])); |
| 56 | + } |
| 57 | +} |
0 commit comments