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 | * Initializes reflection instance for the method node |
||
35 | * |
||
36 | * @param string $className Name of the class |
||
37 | * @param string $methodName Name of the method |
||
38 | * @param ClassMethod $classMethodNode AST-node for method |
||
39 | */ |
||
40 | 25 | public function __construct($className, $methodName, ClassMethod $classMethodNode = null) |
|
49 | |||
50 | /** |
||
51 | * Emulating original behaviour of reflection |
||
52 | */ |
||
53 | public function __debugInfo() |
||
60 | |||
61 | /** |
||
62 | * Returns the string representation of the Reflection method object. |
||
63 | * |
||
64 | * @link http://php.net/manual/en/reflectionmethod.tostring.php |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | 1 | public function __toString() |
|
96 | |||
97 | /** |
||
98 | * {@inheritDoc} |
||
99 | */ |
||
100 | public function getClosure($object) |
||
106 | |||
107 | /** |
||
108 | * {@inheritDoc} |
||
109 | */ |
||
110 | 2 | public function getDeclaringClass() |
|
114 | |||
115 | /** |
||
116 | * {@inheritDoc} |
||
117 | */ |
||
118 | 8 | public function getModifiers() |
|
142 | |||
143 | /** |
||
144 | * {@inheritDoc} |
||
145 | */ |
||
146 | public function getPrototype() |
||
160 | |||
161 | /** |
||
162 | * {@inheritDoc} |
||
163 | */ |
||
164 | public function invoke($object, $args = null) |
||
170 | |||
171 | /** |
||
172 | * {@inheritDoc} |
||
173 | */ |
||
174 | public function invokeArgs($object, array $args) |
||
180 | |||
181 | /** |
||
182 | * {@inheritDoc} |
||
183 | */ |
||
184 | 8 | public function isAbstract() |
|
188 | |||
189 | /** |
||
190 | * {@inheritDoc} |
||
191 | */ |
||
192 | 1 | public function isConstructor() |
|
196 | |||
197 | /** |
||
198 | * {@inheritDoc} |
||
199 | */ |
||
200 | 1 | public function isDestructor() |
|
204 | |||
205 | /** |
||
206 | * {@inheritDoc} |
||
207 | */ |
||
208 | 8 | public function isFinal() |
|
212 | |||
213 | /** |
||
214 | * {@inheritDoc} |
||
215 | */ |
||
216 | 8 | public function isPrivate() |
|
220 | |||
221 | /** |
||
222 | * {@inheritDoc} |
||
223 | */ |
||
224 | 8 | public function isProtected() |
|
228 | |||
229 | /** |
||
230 | * {@inheritDoc} |
||
231 | */ |
||
232 | 11 | public function isPublic() |
|
236 | |||
237 | /** |
||
238 | * {@inheritDoc} |
||
239 | */ |
||
240 | 8 | public function isStatic() |
|
244 | |||
245 | /** |
||
246 | * {@inheritDoc} |
||
247 | */ |
||
248 | public function setAccessible($accessible) |
||
254 | |||
255 | /** |
||
256 | * Parses methods from the concrete class node |
||
257 | * |
||
258 | * @param ClassLike $classLikeNode Class-like node |
||
259 | * @param string $fullClassName FQN of the class |
||
260 | * |
||
261 | * @return array|ReflectionMethod[] |
||
262 | */ |
||
263 | 61 | public static function collectFromClassNode(ClassLike $classLikeNode, $fullClassName) |
|
282 | |||
283 | /** |
||
284 | * Implementation of internal reflection initialization |
||
285 | * |
||
286 | * @return void |
||
287 | */ |
||
288 | protected function __initialize() |
||
292 | |||
293 | /** |
||
294 | * Returns ClassMethod node to prevent all possible type checks with instanceof |
||
295 | * |
||
296 | * @return ClassMethod |
||
297 | */ |
||
298 | 11 | private function getClassMethodNode() |
|
302 | } |
||
303 |