|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of phpDocumentor. |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + * |
| 11 | + * @link http://phpdoc.org |
| 12 | + */ |
| 13 | + |
| 14 | +namespace phpDocumentor\Reflection\DocBlock\Tags; |
| 15 | + |
| 16 | +use Doctrine\Deprecations\Deprecation; |
| 17 | +use phpDocumentor\Reflection\Type; |
| 18 | +use phpDocumentor\Reflection\DocBlock\Description; |
| 19 | +use phpDocumentor\Reflection\DocBlock\Tags\TagWithType; |
| 20 | + |
| 21 | +/** |
| 22 | + * Reflection class for a {@}template tag in a Docblock. |
| 23 | + */ |
| 24 | +final class Template extends TagWithType |
| 25 | +{ |
| 26 | + /** @var non-empty-string */ |
| 27 | + private $templateName; |
| 28 | + |
| 29 | + /** @var ?Type */ |
| 30 | + private $bound; |
| 31 | + |
| 32 | + /** @var ?Type */ |
| 33 | + private $default; |
| 34 | + |
| 35 | + public function __construct(string $templateName, ?Type $bound = null, ?Type $default = null, ?Description $description = null) |
| 36 | + { |
| 37 | + $this->name = 'template'; |
| 38 | + $this->templateName = $templateName; |
| 39 | + $this->bound = $bound; |
| 40 | + $this->default = $default; |
| 41 | + $this->description = $description; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @deprecated Create using static factory is deprecated, |
| 46 | + * this method should not be called directly by library consumers |
| 47 | + */ |
| 48 | + public static function create(string $body) |
| 49 | + { |
| 50 | + Deprecation::trigger( |
| 51 | + 'phpdocumentor/reflection-docblock', |
| 52 | + 'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361', |
| 53 | + 'Create using static factory is deprecated, this method should not be called directly |
| 54 | + by library consumers', |
| 55 | + ); |
| 56 | + return null; |
| 57 | + } |
| 58 | + |
| 59 | + public function getTemplateName(): string |
| 60 | + { |
| 61 | + return $this->templateName; |
| 62 | + } |
| 63 | + |
| 64 | + public function getBound(): ?Type |
| 65 | + { |
| 66 | + return $this->bound; |
| 67 | + } |
| 68 | + |
| 69 | + public function getDefault(): ?Type |
| 70 | + { |
| 71 | + return $this->default; |
| 72 | + } |
| 73 | + |
| 74 | + public function __toString(): string |
| 75 | + { |
| 76 | + $bound = $this->bound !== null ? " of {$this->bound}" : ''; |
| 77 | + $default = $this->default !== null ? " = {$this->default}" : ''; |
| 78 | + |
| 79 | + if ($this->description) { |
| 80 | + $description = $this->description->render(); |
| 81 | + } else { |
| 82 | + $description = ''; |
| 83 | + } |
| 84 | + |
| 85 | + return $this->templateName . $bound . $default . ($description !== '' ? ' ' . $description : ''); |
| 86 | + } |
| 87 | +} |
0 commit comments