Complex classes like ReflectionParameter 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 ReflectionParameter, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class ReflectionParameter extends BaseReflectionParameter |
||
24 | { |
||
25 | use InternalPropertiesEmulationTrait; |
||
26 | |||
27 | /** |
||
28 | * Reflection function or method |
||
29 | * |
||
30 | * @var \ReflectionFunctionAbstract |
||
31 | */ |
||
32 | private $declaringFunction; |
||
33 | |||
34 | /** |
||
35 | * Stores the default value for node (if present) |
||
36 | * |
||
37 | * @var mixed |
||
38 | */ |
||
39 | private $defaultValue = null; |
||
40 | |||
41 | /** |
||
42 | * Whether or not default value is constant |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | private $isDefaultValueConstant = false; |
||
47 | |||
48 | /** |
||
49 | * Name of the constant of default value |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $defaultValueConstantName; |
||
54 | |||
55 | /** |
||
56 | * Index of parameter in the list |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | private $parameterIndex = 0; |
||
61 | |||
62 | /** |
||
63 | * Concrete parameter node |
||
64 | * |
||
65 | * @var Param |
||
66 | */ |
||
67 | private $parameterNode; |
||
68 | |||
69 | /** |
||
70 | * Initializes a reflection for the property |
||
71 | * |
||
72 | * @param string|array $unusedFunctionName Name of the function/method |
||
73 | * @param string $parameterName Name of the parameter to reflect |
||
74 | * @param Param $parameterNode Parameter definition node |
||
75 | * @param int $parameterIndex Index of parameter |
||
76 | * @param \ReflectionFunctionAbstract $declaringFunction |
||
77 | */ |
||
78 | 31 | public function __construct( |
|
106 | |||
107 | /** |
||
108 | * Emulating original behaviour of reflection |
||
109 | */ |
||
110 | 1 | public function ___debugInfo() |
|
116 | |||
117 | /** |
||
118 | * Returns string representation of this parameter. |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | 20 | public function __toString() |
|
152 | |||
153 | /** |
||
154 | * {@inheritDoc} |
||
155 | */ |
||
156 | 21 | public function allowsNull() |
|
170 | |||
171 | /** |
||
172 | * {@inheritDoc} |
||
173 | */ |
||
174 | 3 | public function canBePassedByValue() |
|
178 | |||
179 | /** |
||
180 | * @inheritDoc |
||
181 | */ |
||
182 | 2 | public function getClass() |
|
207 | |||
208 | /** |
||
209 | * {@inheritDoc} |
||
210 | */ |
||
211 | 3 | public function getDeclaringClass() |
|
219 | |||
220 | /** |
||
221 | * {@inheritDoc} |
||
222 | */ |
||
223 | 14 | public function getDeclaringFunction() |
|
227 | |||
228 | /** |
||
229 | * {@inheritDoc} |
||
230 | */ |
||
231 | 12 | public function getDefaultValue() |
|
239 | |||
240 | /** |
||
241 | * {@inheritDoc} |
||
242 | */ |
||
243 | 6 | public function getDefaultValueConstantName() |
|
251 | |||
252 | /** |
||
253 | * @inheritDoc |
||
254 | */ |
||
255 | 21 | public function getName() |
|
259 | |||
260 | /** |
||
261 | * {@inheritDoc} |
||
262 | */ |
||
263 | 3 | public function getPosition() |
|
267 | |||
268 | /** |
||
269 | * @inheritDoc |
||
270 | */ |
||
271 | 21 | public function getType() |
|
290 | |||
291 | /** |
||
292 | * @inheritDoc |
||
293 | */ |
||
294 | 4 | public function hasType() |
|
300 | |||
301 | /** |
||
302 | * @inheritDoc |
||
303 | */ |
||
304 | 3 | public function isArray() |
|
308 | |||
309 | /** |
||
310 | * @inheritDoc |
||
311 | */ |
||
312 | 3 | public function isCallable() |
|
316 | |||
317 | /** |
||
318 | * @inheritDoc |
||
319 | */ |
||
320 | 45 | public function isDefaultValueAvailable() |
|
324 | |||
325 | /** |
||
326 | * {@inheritDoc} |
||
327 | */ |
||
328 | 5 | public function isDefaultValueConstant() |
|
332 | |||
333 | /** |
||
334 | * {@inheritDoc} |
||
335 | */ |
||
336 | 36 | public function isOptional() |
|
340 | |||
341 | /** |
||
342 | * @inheritDoc |
||
343 | */ |
||
344 | 20 | public function isPassedByReference() |
|
348 | |||
349 | /** |
||
350 | * @inheritDoc |
||
351 | */ |
||
352 | 52 | public function isVariadic() |
|
356 | |||
357 | /** |
||
358 | * Returns if all following parameters have a default value definition. |
||
359 | * |
||
360 | * @return bool |
||
361 | * @throws ReflectionException If could not fetch declaring function reflection |
||
362 | */ |
||
363 | 14 | protected function haveSiblingsDefalutValues() |
|
380 | } |
||
381 |