| 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: | ?string $static = null, |
| 27: | ?string $self = null, |
| 28: | array $aliases = [] |
| 29: | ) { |
| 30: | if ($isReadOnly && $isWriteOnly) { |
| 31: | throw new InvalidArgumentException('$isReadOnly and $isWriteOnly cannot both be true'); |
| 32: | } |
| 33: | parent::__construct('property', $name, $type, $description, $class, $member, $static, $self, $aliases); |
| 34: | $this->IsReadOnly = $isReadOnly; |
| 35: | $this->IsWriteOnly = $isWriteOnly; |
| 36: | } |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | public function getName(): string |
| 42: | { |
| 43: | return $this->Name; |
| 44: | } |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | public function isReadOnly(): bool |
| 50: | { |
| 51: | return $this->IsReadOnly; |
| 52: | } |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | public function isWriteOnly(): bool |
| 58: | { |
| 59: | return $this->IsWriteOnly; |
| 60: | } |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | public function __toString(): string |
| 66: | { |
| 67: | $string = "@{$this->Tag}"; |
| 68: | if ($this->IsReadOnly) { |
| 69: | $string .= '-read'; |
| 70: | } elseif ($this->IsWriteOnly) { |
| 71: | $string .= '-write'; |
| 72: | } |
| 73: | if (isset($this->Type)) { |
| 74: | $string .= " {$this->Type}"; |
| 75: | } |
| 76: | $string .= " \${$this->Name}"; |
| 77: | if ($this->Description !== null) { |
| 78: | $string .= " {$this->Description}"; |
| 79: | } |
| 80: | return $string; |
| 81: | } |
| 82: | } |
| 83: | |