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 |
||
22 | class ReflectionMethod extends BaseReflectionMethod |
||
23 | { |
||
24 | use ReflectionFunctionLikeTrait, InternalPropertiesEmulationTrait; |
||
25 | |||
26 | /** |
||
27 | * Name of the class |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $className; |
||
32 | |||
33 | /** |
||
34 | * Optional declaring class reference |
||
35 | * |
||
36 | * @var ReflectionClass |
||
37 | */ |
||
38 | private $declaringClass; |
||
39 | |||
40 | /** |
||
41 | * Initializes reflection instance for the method node |
||
42 | * |
||
43 | * @param string $className Name of the class |
||
44 | * @param string $methodName Name of the method |
||
45 | * @param ClassMethod $classMethodNode AST-node for method |
||
46 | * @param ReflectionClass $declaringClass Optional declaring class |
||
47 | */ |
||
48 | 46 | public function __construct( |
|
62 | |||
63 | /** |
||
64 | * Returns an AST-node for method |
||
65 | * |
||
66 | * @return ClassMethod |
||
67 | */ |
||
68 | public function getNode() |
||
72 | |||
73 | /** |
||
74 | * Emulating original behaviour of reflection |
||
75 | */ |
||
76 | 1 | public function ___debugInfo() |
|
83 | |||
84 | /** |
||
85 | * Returns the string representation of the Reflection method object. |
||
86 | * |
||
87 | * @link http://php.net/manual/en/reflectionmethod.tostring.php |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | 64 | public function __toString() |
|
137 | |||
138 | /** |
||
139 | * {@inheritDoc} |
||
140 | */ |
||
141 | 1 | public function getClosure($object) |
|
147 | |||
148 | /** |
||
149 | * {@inheritDoc} |
||
150 | */ |
||
151 | 138 | public function getDeclaringClass() |
|
155 | |||
156 | /** |
||
157 | * {@inheritDoc} |
||
158 | */ |
||
159 | 68 | public function getModifiers() |
|
183 | |||
184 | /** |
||
185 | * {@inheritDoc} |
||
186 | */ |
||
187 | 65 | public function getPrototype() |
|
201 | |||
202 | /** |
||
203 | * {@inheritDoc} |
||
204 | */ |
||
205 | 1 | public function invoke($object, $args = null) |
|
211 | |||
212 | /** |
||
213 | * {@inheritDoc} |
||
214 | */ |
||
215 | 3 | public function invokeArgs($object, array $args) |
|
221 | |||
222 | /** |
||
223 | * {@inheritDoc} |
||
224 | */ |
||
225 | 132 | public function isAbstract() |
|
229 | |||
230 | /** |
||
231 | * {@inheritDoc} |
||
232 | */ |
||
233 | 128 | public function isConstructor() |
|
237 | |||
238 | /** |
||
239 | * {@inheritDoc} |
||
240 | */ |
||
241 | 128 | public function isDestructor() |
|
245 | |||
246 | /** |
||
247 | * {@inheritDoc} |
||
248 | */ |
||
249 | 132 | public function isFinal() |
|
253 | |||
254 | /** |
||
255 | * {@inheritDoc} |
||
256 | */ |
||
257 | 132 | public function isPrivate() |
|
261 | |||
262 | /** |
||
263 | * {@inheritDoc} |
||
264 | */ |
||
265 | 132 | public function isProtected() |
|
269 | |||
270 | /** |
||
271 | * {@inheritDoc} |
||
272 | */ |
||
273 | 135 | public function isPublic() |
|
277 | |||
278 | /** |
||
279 | * {@inheritDoc} |
||
280 | */ |
||
281 | 132 | public function isStatic() |
|
285 | |||
286 | /** |
||
287 | * {@inheritDoc} |
||
288 | */ |
||
289 | 1 | public function setAccessible($accessible) |
|
295 | |||
296 | /** |
||
297 | * Parses methods from the concrete class node |
||
298 | * |
||
299 | * @param ClassLike $classLikeNode Class-like node |
||
300 | * @param ReflectionClass $reflectionClass Reflection of the class |
||
301 | * |
||
302 | * @return array|ReflectionMethod[] |
||
303 | */ |
||
304 | 60 | public static function collectFromClassNode(ClassLike $classLikeNode, ReflectionClass $reflectionClass) |
|
324 | |||
325 | /** |
||
326 | * Implementation of internal reflection initialization |
||
327 | * |
||
328 | * @return void |
||
329 | */ |
||
330 | 69 | protected function __initialize() |
|
334 | |||
335 | /** |
||
336 | * Returns ClassMethod node to prevent all possible type checks with instanceof |
||
337 | * |
||
338 | * @return ClassMethod |
||
339 | */ |
||
340 | 581 | private function getClassMethodNode() |
|
344 | } |
||
345 |