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 |
||
22 | class ReflectionParameter extends BaseReflectionParameter |
||
23 | { |
||
24 | use InternalPropertiesEmulationTrait; |
||
25 | |||
26 | /** |
||
27 | * Reflection function or method |
||
28 | * |
||
29 | * @var \ReflectionFunctionAbstract |
||
30 | */ |
||
31 | private $declaringFunction; |
||
32 | |||
33 | /** |
||
34 | * Stores the default value for node (if present) |
||
35 | * |
||
36 | * @var mixed |
||
37 | */ |
||
38 | private $defaultValue = null; |
||
39 | |||
40 | /** |
||
41 | * Whether or not default value is constant |
||
42 | * |
||
43 | * @var bool |
||
44 | */ |
||
45 | private $isDefaultValueConstant = false; |
||
46 | |||
47 | /** |
||
48 | * Name of the constant of default value |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $defaultValueConstantName; |
||
53 | |||
54 | /** |
||
55 | * Index of parameter in the list |
||
56 | * |
||
57 | * @var int |
||
58 | */ |
||
59 | private $parameterIndex = 0; |
||
60 | |||
61 | /** |
||
62 | * Concrete parameter node |
||
63 | * |
||
64 | * @var Param |
||
65 | */ |
||
66 | private $parameterNode; |
||
67 | |||
68 | /** |
||
69 | * Initializes a reflection for the property |
||
70 | * |
||
71 | * @param string|array $unusedFunctionName Name of the function/method |
||
72 | * @param string $parameterName Name of the parameter to reflect |
||
73 | * @param Param $parameterNode Parameter definition node |
||
74 | * @param int $parameterIndex Index of parameter |
||
75 | * @param \ReflectionFunctionAbstract $declaringFunction |
||
76 | */ |
||
77 | 9 | public function __construct( |
|
105 | |||
106 | /** |
||
107 | * Emulating original behaviour of reflection |
||
108 | */ |
||
109 | 1 | public function __debugInfo() |
|
115 | |||
116 | /** |
||
117 | * Returns string representation of this parameter. |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | 3 | public function __toString() |
|
150 | |||
151 | /** |
||
152 | * {@inheritDoc} |
||
153 | */ |
||
154 | 1 | public function allowsNull() |
|
163 | |||
164 | /** |
||
165 | * {@inheritDoc} |
||
166 | */ |
||
167 | 1 | public function canBePassedByValue() |
|
171 | |||
172 | /** |
||
173 | * @inheritDoc |
||
174 | */ |
||
175 | 1 | public function getClass() |
|
190 | |||
191 | /** |
||
192 | * {@inheritDoc} |
||
193 | */ |
||
194 | 2 | public function getDeclaringClass() |
|
202 | |||
203 | /** |
||
204 | * {@inheritDoc} |
||
205 | */ |
||
206 | 3 | public function getDeclaringFunction() |
|
210 | |||
211 | /** |
||
212 | * {@inheritDoc} |
||
213 | */ |
||
214 | 4 | public function getDefaultValue() |
|
222 | |||
223 | /** |
||
224 | * {@inheritDoc} |
||
225 | */ |
||
226 | 2 | public function getDefaultValueConstantName() |
|
234 | |||
235 | /** |
||
236 | * @inheritDoc |
||
237 | */ |
||
238 | 3 | public function getName() |
|
242 | |||
243 | /** |
||
244 | * {@inheritDoc} |
||
245 | */ |
||
246 | 1 | public function getPosition() |
|
250 | |||
251 | /** |
||
252 | * @inheritDoc |
||
253 | */ |
||
254 | 1 | public function isArray() |
|
258 | |||
259 | /** |
||
260 | * @inheritDoc |
||
261 | */ |
||
262 | 1 | public function isCallable() |
|
266 | |||
267 | /** |
||
268 | * @inheritDoc |
||
269 | */ |
||
270 | 9 | public function isDefaultValueAvailable() |
|
274 | |||
275 | /** |
||
276 | * {@inheritDoc} |
||
277 | */ |
||
278 | 1 | public function isDefaultValueConstant() |
|
282 | |||
283 | /** |
||
284 | * {@inheritDoc} |
||
285 | */ |
||
286 | 3 | public function isOptional() |
|
290 | |||
291 | /** |
||
292 | * @inheritDoc |
||
293 | */ |
||
294 | 3 | public function isPassedByReference() |
|
298 | |||
299 | /** |
||
300 | * @inheritDoc |
||
301 | */ |
||
302 | 3 | public function isVariadic() |
|
306 | |||
307 | /** |
||
308 | * Returns if all following parameters have a default value definition. |
||
309 | * |
||
310 | * @return bool |
||
311 | * @throws ReflectionException If could not fetch declaring function reflection |
||
312 | */ |
||
313 | 3 | protected function haveSiblingsDefalutValues() |
|
330 | } |
||
331 |