| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\PHPDoc\Tag; |
| 4: | |
| 5: | use Salient\Utility\Arr; |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | class MethodTag extends AbstractTag |
| 11: | { |
| 12: | |
| 13: | protected array $Params; |
| 14: | protected bool $IsStatic; |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | public function __construct( |
| 22: | string $name, |
| 23: | ?string $type = null, |
| 24: | array $params = [], |
| 25: | bool $isStatic = false, |
| 26: | ?string $description = null, |
| 27: | ?string $class = null, |
| 28: | ?string $member = null, |
| 29: | ?string $static = null, |
| 30: | ?string $self = null, |
| 31: | array $aliases = [] |
| 32: | ) { |
| 33: | parent::__construct('method', $name, $type, $description, $class, $member, $static, $self, $aliases); |
| 34: | $this->Params = $this->filterParams($params, $aliases); |
| 35: | $this->IsStatic = $isStatic; |
| 36: | } |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | public function getName(): string |
| 42: | { |
| 43: | return $this->Name; |
| 44: | } |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | public function getParams(): array |
| 52: | { |
| 53: | return $this->Params; |
| 54: | } |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | public function isStatic(): bool |
| 60: | { |
| 61: | return $this->IsStatic; |
| 62: | } |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | public function __toString(): string |
| 68: | { |
| 69: | $string = "@{$this->Tag} "; |
| 70: | if ($this->IsStatic) { |
| 71: | $string .= 'static '; |
| 72: | } |
| 73: | if (isset($this->Type)) { |
| 74: | $string .= "{$this->Type} "; |
| 75: | } |
| 76: | $string .= "{$this->Name}("; |
| 77: | $string .= Arr::implode(', ', $this->Params, ''); |
| 78: | $string .= ')'; |
| 79: | if ($this->Description !== null) { |
| 80: | $string .= " {$this->Description}"; |
| 81: | } |
| 82: | return $string; |
| 83: | } |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: | final protected function filterParams(array $params, array $aliases = []): array |
| 91: | { |
| 92: | foreach ($params as $param) { |
| 93: | $name = $this->filterString($param->getName(), 'parameter name'); |
| 94: | $filtered[$name] = $param->withType($this->filterType($param->getType(), $aliases)); |
| 95: | } |
| 96: | |
| 97: | return $filtered ?? []; |
| 98: | } |
| 99: | } |
| 100: | |