1: | <?php declare(strict_types=1); |
2: | |
3: | namespace PhpParser\Node\Stmt; |
4: | |
5: | use PhpParser\Modifiers; |
6: | use PhpParser\Node; |
7: | use PhpParser\Node\FunctionLike; |
8: | |
9: | class ClassMethod extends Node\Stmt implements FunctionLike { |
10: | |
11: | public int $flags; |
12: | |
13: | public bool $byRef; |
14: | |
15: | public Node\Identifier $name; |
16: | |
17: | public array $params; |
18: | |
19: | public ?Node $returnType; |
20: | |
21: | public ?array $stmts; |
22: | |
23: | public array $attrGroups; |
24: | |
25: | |
26: | private static array $magicNames = [ |
27: | '__construct' => true, |
28: | '__destruct' => true, |
29: | '__call' => true, |
30: | '__callstatic' => true, |
31: | '__get' => true, |
32: | '__set' => true, |
33: | '__isset' => true, |
34: | '__unset' => true, |
35: | '__sleep' => true, |
36: | '__wakeup' => true, |
37: | '__tostring' => true, |
38: | '__set_state' => true, |
39: | '__clone' => true, |
40: | '__invoke' => true, |
41: | '__debuginfo' => true, |
42: | '__serialize' => true, |
43: | '__unserialize' => true, |
44: | ]; |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | public function __construct($name, array $subNodes = [], array $attributes = []) { |
67: | $this->attributes = $attributes; |
68: | $this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0; |
69: | $this->byRef = $subNodes['byRef'] ?? false; |
70: | $this->name = \is_string($name) ? new Node\Identifier($name) : $name; |
71: | $this->params = $subNodes['params'] ?? []; |
72: | $this->returnType = $subNodes['returnType'] ?? null; |
73: | $this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : []; |
74: | $this->attrGroups = $subNodes['attrGroups'] ?? []; |
75: | } |
76: | |
77: | public function getSubNodeNames(): array { |
78: | return ['attrGroups', 'flags', 'byRef', 'name', 'params', 'returnType', 'stmts']; |
79: | } |
80: | |
81: | public function returnsByRef(): bool { |
82: | return $this->byRef; |
83: | } |
84: | |
85: | public function getParams(): array { |
86: | return $this->params; |
87: | } |
88: | |
89: | public function getReturnType() { |
90: | return $this->returnType; |
91: | } |
92: | |
93: | public function getStmts(): ?array { |
94: | return $this->stmts; |
95: | } |
96: | |
97: | public function getAttrGroups(): array { |
98: | return $this->attrGroups; |
99: | } |
100: | |
101: | |
102: | |
103: | |
104: | public function isPublic(): bool { |
105: | return ($this->flags & Modifiers::PUBLIC) !== 0 |
106: | || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; |
107: | } |
108: | |
109: | |
110: | |
111: | |
112: | public function isProtected(): bool { |
113: | return (bool) ($this->flags & Modifiers::PROTECTED); |
114: | } |
115: | |
116: | |
117: | |
118: | |
119: | public function isPrivate(): bool { |
120: | return (bool) ($this->flags & Modifiers::PRIVATE); |
121: | } |
122: | |
123: | |
124: | |
125: | |
126: | public function isAbstract(): bool { |
127: | return (bool) ($this->flags & Modifiers::ABSTRACT); |
128: | } |
129: | |
130: | |
131: | |
132: | |
133: | public function isFinal(): bool { |
134: | return (bool) ($this->flags & Modifiers::FINAL); |
135: | } |
136: | |
137: | |
138: | |
139: | |
140: | public function isStatic(): bool { |
141: | return (bool) ($this->flags & Modifiers::STATIC); |
142: | } |
143: | |
144: | |
145: | |
146: | |
147: | public function isMagic(): bool { |
148: | return isset(self::$magicNames[$this->name->toLowerString()]); |
149: | } |
150: | |
151: | public function getType(): string { |
152: | return 'Stmt_ClassMethod'; |
153: | } |
154: | } |
155: | |