1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\PHPDoc\Tag; |
4: | |
5: | use InvalidArgumentException; |
6: | |
7: | |
8: | |
9: | |
10: | class PropertyTag extends AbstractTag |
11: | { |
12: | protected bool $IsReadOnly; |
13: | protected bool $IsWriteOnly; |
14: | |
15: | |
16: | |
17: | |
18: | public function __construct( |
19: | string $name, |
20: | ?string $type = null, |
21: | bool $isReadOnly = false, |
22: | bool $isWriteOnly = false, |
23: | ?string $description = null, |
24: | ?string $class = null, |
25: | ?string $member = null, |
26: | array $aliases = [] |
27: | ) { |
28: | if ($isReadOnly && $isWriteOnly) { |
29: | throw new InvalidArgumentException('$isReadOnly and $isWriteOnly cannot both be true'); |
30: | } |
31: | parent::__construct('property', $name, $type, $description, $class, $member, $aliases); |
32: | $this->IsReadOnly = $isReadOnly; |
33: | $this->IsWriteOnly = $isWriteOnly; |
34: | } |
35: | |
36: | |
37: | |
38: | |
39: | public function getName(): string |
40: | { |
41: | return $this->Name; |
42: | } |
43: | |
44: | |
45: | |
46: | |
47: | public function isReadOnly(): bool |
48: | { |
49: | return $this->IsReadOnly; |
50: | } |
51: | |
52: | |
53: | |
54: | |
55: | public function isWriteOnly(): bool |
56: | { |
57: | return $this->IsWriteOnly; |
58: | } |
59: | |
60: | |
61: | |
62: | |
63: | public function __toString(): string |
64: | { |
65: | $string = "@{$this->Tag}"; |
66: | if ($this->IsReadOnly) { |
67: | $string .= '-read'; |
68: | } elseif ($this->IsWriteOnly) { |
69: | $string .= '-write'; |
70: | } |
71: | if (isset($this->Type)) { |
72: | $string .= " {$this->Type}"; |
73: | } |
74: | $string .= " \${$this->Name}"; |
75: | if ($this->Description !== null) { |
76: | $string .= " {$this->Description}"; |
77: | } |
78: | return $string; |
79: | } |
80: | } |
81: | |