1 | <?php |
||
21 | final class Methods |
||
22 | { |
||
23 | private const MAGIC_METHODS = [ |
||
24 | '__construct', |
||
25 | '__destruct', |
||
26 | '__call', |
||
27 | '__callStatic', |
||
28 | '__get', |
||
29 | '__set', |
||
30 | '__isset', |
||
31 | '__unset', |
||
32 | '__sleep', |
||
33 | '__wakeup', |
||
34 | '__toString', |
||
35 | '__invoke', |
||
36 | '__set_state', |
||
37 | '__debugInfo', |
||
38 | ]; |
||
39 | |||
40 | private const RESERVED_UNQUALIFIED_RETURN_TYPES = ['self', 'static', 'object']; |
||
41 | |||
42 | /** |
||
43 | * @param Traverser $traverser |
||
44 | * @param Parser|null $parser |
||
45 | */ |
||
46 | public function __construct( |
||
53 | |||
54 | /** |
||
55 | * @param \ReflectionClass $reflection |
||
56 | * @return array |
||
57 | */ |
||
58 | public function getMethods(\ReflectionClass $reflection): array |
||
85 | |||
86 | /** |
||
87 | * @param \ReflectionMethod $method |
||
88 | * @return bool |
||
89 | */ |
||
90 | private function isIgnoredMethod(\ReflectionMethod $method): bool |
||
94 | |||
95 | /** |
||
96 | * @param string $name |
||
97 | * @return bool |
||
98 | */ |
||
99 | private function isMagicMethod(string $name): bool |
||
103 | |||
104 | /** |
||
105 | * @param \ReflectionMethod $method |
||
106 | * @return int |
||
107 | */ |
||
108 | private function packFlags(\ReflectionMethod $method): int |
||
121 | |||
122 | /** |
||
123 | * @param \ReflectionMethod $method |
||
124 | * @return Node|null |
||
125 | */ |
||
126 | private function defineReturnType(\ReflectionMethod $method): ?Node |
||
151 | |||
152 | /** |
||
153 | * @param \ReflectionMethod $method |
||
154 | * @param string $name |
||
155 | * @return string |
||
156 | */ |
||
157 | private function replacedSelfReturnTypeName(\ReflectionMethod $method, string $name): string |
||
161 | |||
162 | /** |
||
163 | * @param \ReflectionType $returnType |
||
164 | * @param string $name |
||
165 | * @return bool |
||
166 | */ |
||
167 | private function returnTypeShouldBeQualified(\ReflectionType $returnType, string $name): bool |
||
175 | |||
176 | /** |
||
177 | * @param \ReflectionMethod $method |
||
178 | * @return array |
||
179 | */ |
||
180 | private function packParams(\ReflectionMethod $method): array |
||
196 | |||
197 | /** |
||
198 | * @param \ReflectionParameter $parameter |
||
199 | * @return string|null |
||
200 | */ |
||
201 | private function defineParamReturnType(\ReflectionParameter $parameter): ?string |
||
219 | |||
220 | /** |
||
221 | * @param \ReflectionClass[] $reflections |
||
222 | * @return Node\Stmt\ClassMethod[] |
||
223 | */ |
||
224 | private function getExtendedMethodNodes(array $reflections): array |
||
244 | } |
||
245 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: