Complex classes like ReflectionMethod often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ReflectionMethod, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | class ReflectionMethod extends BaseReflectionMethod |
||
25 | { |
||
26 | use InternalPropertiesEmulationTrait; |
||
27 | use ReflectionFunctionLikeTrait; |
||
28 | |||
29 | /** |
||
30 | * Name of the class |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | private $className; |
||
35 | |||
36 | /** |
||
37 | * Optional declaring class reference |
||
38 | * |
||
39 | * @var ReflectionClass |
||
40 | */ |
||
41 | private $declaringClass; |
||
42 | |||
43 | /** |
||
44 | * Initializes reflection instance for the method node |
||
45 | * |
||
46 | * @param string $className Name of the class |
||
47 | * @param string $methodName Name of the method |
||
48 | * @param ?ClassMethod $classMethodNode AST-node for method |
||
|
|||
49 | * @param ?ReflectionClass $declaringClass Optional declaring class |
||
50 | */ |
||
51 | 43 | public function __construct( |
|
65 | |||
66 | /** |
||
67 | * Returns an AST-node for method |
||
68 | */ |
||
69 | public function getNode(): ClassMethod |
||
73 | |||
74 | /** |
||
75 | * Emulating original behaviour of reflection |
||
76 | */ |
||
77 | 1 | public function __debugInfo(): array |
|
84 | |||
85 | /** |
||
86 | * Returns the string representation of the Reflection method object. |
||
87 | * |
||
88 | * @link http://php.net/manual/en/reflectionmethod.tostring.php |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | 64 | public function __toString() |
|
138 | |||
139 | /** |
||
140 | * {@inheritDoc} |
||
141 | */ |
||
142 | 1 | public function getClosure($object = null) |
|
148 | |||
149 | /** |
||
150 | * {@inheritDoc} |
||
151 | */ |
||
152 | 135 | public function getDeclaringClass() |
|
156 | |||
157 | /** |
||
158 | * {@inheritDoc} |
||
159 | */ |
||
160 | 65 | public function getModifiers() |
|
184 | |||
185 | /** |
||
186 | * {@inheritDoc} |
||
187 | */ |
||
188 | 65 | public function getPrototype() |
|
202 | |||
203 | /** |
||
204 | * {@inheritDoc} |
||
205 | */ |
||
206 | 1 | public function invoke($object, $args = null) |
|
212 | |||
213 | /** |
||
214 | * {@inheritDoc} |
||
215 | */ |
||
216 | 3 | public function invokeArgs($object, array $args) |
|
222 | |||
223 | /** |
||
224 | * {@inheritDoc} |
||
225 | */ |
||
226 | 129 | public function isAbstract() |
|
230 | |||
231 | /** |
||
232 | * {@inheritDoc} |
||
233 | */ |
||
234 | 128 | public function isConstructor() |
|
238 | |||
239 | /** |
||
240 | * {@inheritDoc} |
||
241 | */ |
||
242 | 128 | public function isDestructor() |
|
246 | |||
247 | /** |
||
248 | * {@inheritDoc} |
||
249 | */ |
||
250 | 129 | public function isFinal() |
|
254 | |||
255 | /** |
||
256 | * {@inheritDoc} |
||
257 | */ |
||
258 | 129 | public function isPrivate() |
|
262 | |||
263 | /** |
||
264 | * {@inheritDoc} |
||
265 | */ |
||
266 | 129 | public function isProtected() |
|
270 | |||
271 | /** |
||
272 | * {@inheritDoc} |
||
273 | */ |
||
274 | 132 | public function isPublic() |
|
278 | |||
279 | /** |
||
280 | * {@inheritDoc} |
||
281 | */ |
||
282 | 129 | public function isStatic() |
|
286 | |||
287 | /** |
||
288 | * {@inheritDoc} |
||
289 | */ |
||
290 | 1 | public function setAccessible($accessible) |
|
296 | |||
297 | /** |
||
298 | * Parses methods from the concrete class node |
||
299 | * |
||
300 | * @param ClassLike $classLikeNode Class-like node |
||
301 | * @param ReflectionClass $reflectionClass Reflection of the class |
||
302 | * |
||
303 | * @return ReflectionMethod[] |
||
304 | */ |
||
305 | 56 | public static function collectFromClassNode(ClassLike $classLikeNode, ReflectionClass $reflectionClass): array |
|
325 | |||
326 | /** |
||
327 | * Implementation of internal reflection initialization |
||
328 | */ |
||
329 | 69 | protected function __initialize(): void |
|
333 | |||
334 | /** |
||
335 | * Returns ClassMethod node to prevent all possible type checks with instanceof |
||
336 | */ |
||
337 | 578 | private function getClassMethodNode(): ClassMethod |
|
341 | } |
||
342 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.