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