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 | 31 | public function __construct($className, $methodName, ClassMethod $classMethodNode = null) |
|
49 | |||
50 | /** |
||
51 | * Emulating original behaviour of reflection |
||
52 | */ |
||
53 | 1 | 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() |
|
103 | |||
104 | /** |
||
105 | * {@inheritDoc} |
||
106 | */ |
||
107 | 1 | public function getClosure($object) |
|
113 | |||
114 | /** |
||
115 | * {@inheritDoc} |
||
116 | */ |
||
117 | 3 | public function getDeclaringClass() |
|
121 | |||
122 | /** |
||
123 | * {@inheritDoc} |
||
124 | */ |
||
125 | 8 | public function getModifiers() |
|
149 | |||
150 | /** |
||
151 | * {@inheritDoc} |
||
152 | */ |
||
153 | 2 | public function getPrototype() |
|
167 | |||
168 | /** |
||
169 | * {@inheritDoc} |
||
170 | */ |
||
171 | 1 | public function invoke($object, $args = null) |
|
177 | |||
178 | /** |
||
179 | * {@inheritDoc} |
||
180 | */ |
||
181 | 3 | public function invokeArgs($object, array $args) |
|
187 | |||
188 | /** |
||
189 | * {@inheritDoc} |
||
190 | */ |
||
191 | 8 | public function isAbstract() |
|
195 | |||
196 | /** |
||
197 | * {@inheritDoc} |
||
198 | */ |
||
199 | 1 | public function isConstructor() |
|
203 | |||
204 | /** |
||
205 | * {@inheritDoc} |
||
206 | */ |
||
207 | 1 | public function isDestructor() |
|
211 | |||
212 | /** |
||
213 | * {@inheritDoc} |
||
214 | */ |
||
215 | 8 | public function isFinal() |
|
219 | |||
220 | /** |
||
221 | * {@inheritDoc} |
||
222 | */ |
||
223 | 8 | public function isPrivate() |
|
227 | |||
228 | /** |
||
229 | * {@inheritDoc} |
||
230 | */ |
||
231 | 8 | public function isProtected() |
|
235 | |||
236 | /** |
||
237 | * {@inheritDoc} |
||
238 | */ |
||
239 | 11 | public function isPublic() |
|
243 | |||
244 | /** |
||
245 | * {@inheritDoc} |
||
246 | */ |
||
247 | 8 | public function isStatic() |
|
251 | |||
252 | /** |
||
253 | * {@inheritDoc} |
||
254 | */ |
||
255 | 1 | public function setAccessible($accessible) |
|
261 | |||
262 | /** |
||
263 | * Parses methods from the concrete class node |
||
264 | * |
||
265 | * @param ClassLike $classLikeNode Class-like node |
||
266 | * @param string $fullClassName FQN of the class |
||
267 | * |
||
268 | * @return array|ReflectionMethod[] |
||
269 | */ |
||
270 | 66 | public static function collectFromClassNode(ClassLike $classLikeNode, $fullClassName) |
|
289 | |||
290 | /** |
||
291 | * Implementation of internal reflection initialization |
||
292 | * |
||
293 | * @return void |
||
294 | */ |
||
295 | 5 | protected function __initialize() |
|
299 | |||
300 | /** |
||
301 | * Returns ClassMethod node to prevent all possible type checks with instanceof |
||
302 | * |
||
303 | * @return ClassMethod |
||
304 | */ |
||
305 | 12 | private function getClassMethodNode() |
|
309 | } |
||
310 |