1: <?php declare(strict_types=1);
2:
3: namespace Salient\PHPDoc\Tag;
4:
5: /**
6: * @api
7: */
8: class VarTag extends AbstractTag
9: {
10: /**
11: * Creates a new VarTag object
12: */
13: public function __construct(
14: string $type,
15: ?string $name = null,
16: ?string $description = null,
17: ?string $class = null,
18: ?string $member = null,
19: array $aliases = []
20: ) {
21: parent::__construct('var', $name, $type, $description, $class, $member, $aliases);
22: }
23:
24: /**
25: * @inheritDoc
26: */
27: public function getType(): string
28: {
29: return $this->Type;
30: }
31:
32: /**
33: * Get an instance with the given name
34: *
35: * @return static
36: */
37: public function withName(?string $name)
38: {
39: if ($name === null) {
40: return $this->without('Name');
41: }
42: return $this->with('Name', $this->filterString($name, 'name'));
43: }
44:
45: /**
46: * @inheritDoc
47: */
48: public function __toString(): string
49: {
50: $string = "@{$this->Tag} {$this->Type}";
51: if (isset($this->Name)) {
52: $string .= " \${$this->Name}";
53: }
54: if ($this->Description !== null) {
55: $string .= " {$this->Description}";
56: }
57: return $string;
58: }
59: }
60: