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 |
||
21 | class ReflectionMethod extends BaseReflectionMethod |
||
22 | { |
||
23 | use ReflectionFunctionLikeTrait; |
||
24 | |||
25 | /** |
||
26 | * Name of the class |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $className; |
||
31 | |||
32 | /** |
||
33 | * Initializes reflection instance for the method node |
||
34 | * |
||
35 | * @param string $className Name of the class |
||
36 | * @param string $methodName Name of the method |
||
37 | * @param ClassMethod $classMethodNode AST-node for method |
||
38 | */ |
||
39 | 4 | public function __construct($className, $methodName, ClassMethod $classMethodNode = null) |
|
45 | |||
46 | /** |
||
47 | * Emulating original behaviour of reflection |
||
48 | */ |
||
49 | public function __debugInfo() |
||
56 | |||
57 | /** |
||
58 | * Returns the string representation of the Reflection method object. |
||
59 | * |
||
60 | * @link http://php.net/manual/en/reflectionmethod.tostring.php |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | 1 | public function __toString() |
|
92 | |||
93 | /** |
||
94 | * {@inheritDoc} |
||
95 | */ |
||
96 | public function getClosure($object) |
||
102 | |||
103 | /** |
||
104 | * {@inheritDoc} |
||
105 | */ |
||
106 | 2 | public function getDeclaringClass() |
|
110 | |||
111 | /** |
||
112 | * {@inheritDoc} |
||
113 | */ |
||
114 | 1 | public function getModifiers() |
|
138 | |||
139 | /** |
||
140 | * {@inheritDoc} |
||
141 | */ |
||
142 | public function getPrototype() |
||
156 | |||
157 | /** |
||
158 | * {@inheritDoc} |
||
159 | */ |
||
160 | public function invoke($object, $args = null) |
||
166 | |||
167 | /** |
||
168 | * {@inheritDoc} |
||
169 | */ |
||
170 | public function invokeArgs($object, array $args) |
||
176 | |||
177 | /** |
||
178 | * {@inheritDoc} |
||
179 | */ |
||
180 | 1 | public function isAbstract() |
|
184 | |||
185 | /** |
||
186 | * {@inheritDoc} |
||
187 | */ |
||
188 | 1 | public function isConstructor() |
|
192 | |||
193 | /** |
||
194 | * {@inheritDoc} |
||
195 | */ |
||
196 | 1 | public function isDestructor() |
|
200 | |||
201 | /** |
||
202 | * {@inheritDoc} |
||
203 | */ |
||
204 | 1 | public function isFinal() |
|
208 | |||
209 | /** |
||
210 | * {@inheritDoc} |
||
211 | */ |
||
212 | 1 | public function isPrivate() |
|
216 | |||
217 | /** |
||
218 | * {@inheritDoc} |
||
219 | */ |
||
220 | 1 | public function isProtected() |
|
224 | |||
225 | /** |
||
226 | * {@inheritDoc} |
||
227 | */ |
||
228 | 2 | public function isPublic() |
|
232 | |||
233 | /** |
||
234 | * {@inheritDoc} |
||
235 | */ |
||
236 | 1 | public function isStatic() |
|
240 | |||
241 | /** |
||
242 | * {@inheritDoc} |
||
243 | */ |
||
244 | public function setAccessible($accessible) |
||
250 | |||
251 | /** |
||
252 | * Parses methods from the concrete class node |
||
253 | * |
||
254 | * @param ClassLike $classLikeNode Class-like node |
||
255 | * @param string $fullClassName FQN of the class |
||
256 | * |
||
257 | * @return array|ReflectionMethod[] |
||
258 | */ |
||
259 | 6 | public static function collectFromClassNode(ClassLike $classLikeNode, $fullClassName) |
|
277 | |||
278 | /** |
||
279 | * Implementation of internal reflection initialization |
||
280 | * |
||
281 | * @return void |
||
282 | */ |
||
283 | protected function __initialize() |
||
287 | |||
288 | /** |
||
289 | * Returns ClassMethod node to prevent all possible type checks with instanceof |
||
290 | * |
||
291 | * @return ClassMethod |
||
292 | */ |
||
293 | 2 | private function getClassMethodNode() |
|
297 | } |
||
298 |