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: | array $aliases = [] |
30: | ) { |
31: | parent::__construct('method', $name, $type, $description, $class, $member, $aliases); |
32: | $this->Params = $this->filterParams($params, $aliases); |
33: | $this->IsStatic = $isStatic; |
34: | } |
35: | |
36: | |
37: | |
38: | |
39: | public function getName(): string |
40: | { |
41: | return $this->Name; |
42: | } |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | public function getParams(): array |
50: | { |
51: | return $this->Params; |
52: | } |
53: | |
54: | |
55: | |
56: | |
57: | public function isStatic(): bool |
58: | { |
59: | return $this->IsStatic; |
60: | } |
61: | |
62: | |
63: | |
64: | |
65: | public function __toString(): string |
66: | { |
67: | $string = "@{$this->Tag} "; |
68: | if ($this->IsStatic) { |
69: | $string .= 'static '; |
70: | } |
71: | if (isset($this->Type)) { |
72: | $string .= "{$this->Type} "; |
73: | } |
74: | $string .= "{$this->Name}("; |
75: | $string .= Arr::implode(', ', $this->Params, ''); |
76: | $string .= ')'; |
77: | if ($this->Description !== null) { |
78: | $string .= " {$this->Description}"; |
79: | } |
80: | return $string; |
81: | } |
82: | |
83: | |
84: | |
85: | |
86: | |
87: | |
88: | final protected function filterParams(array $params, array $aliases = []): array |
89: | { |
90: | foreach ($params as $param) { |
91: | $name = $this->filterString($param->getName(), 'parameter name'); |
92: | $filtered[$name] = $param->withType($this->filterType($param->getType(), $aliases)); |
93: | } |
94: | |
95: | return $filtered ?? []; |
96: | } |
97: | } |
98: | |