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 |
||
26 | class ReflectionParameter extends BaseReflectionParameter |
||
27 | { |
||
28 | use InternalPropertiesEmulationTrait; |
||
29 | |||
30 | /** |
||
31 | * Reflection function or method |
||
32 | * |
||
33 | * @var ReflectionFunctionAbstract |
||
34 | */ |
||
35 | private $declaringFunction; |
||
36 | |||
37 | /** |
||
38 | * Stores the default value for node (if present) |
||
39 | * |
||
40 | * @var mixed |
||
41 | */ |
||
42 | private $defaultValue; |
||
43 | |||
44 | /** |
||
45 | * Whether or not default value is constant |
||
46 | * |
||
47 | * @var bool |
||
48 | */ |
||
49 | private $isDefaultValueConstant = false; |
||
50 | |||
51 | /** |
||
52 | * Name of the constant of default value |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | private $defaultValueConstantName; |
||
57 | |||
58 | /** |
||
59 | * Index of parameter in the list |
||
60 | * |
||
61 | * @var int |
||
62 | */ |
||
63 | private $parameterIndex; |
||
64 | |||
65 | /** |
||
66 | * Concrete parameter node |
||
67 | * |
||
68 | * @var Param |
||
69 | */ |
||
70 | private $parameterNode; |
||
71 | |||
72 | /** |
||
73 | * Initializes a reflection for the property |
||
74 | * |
||
75 | * @param string|array $unusedFunctionName Name of the function/method |
||
76 | * @param string $parameterName Name of the parameter to reflect |
||
77 | * @param ?Param $parameterNode Parameter definition node |
||
|
|||
78 | * @param int $parameterIndex Index of parameter |
||
79 | * @param ?ReflectionFunctionAbstract $declaringFunction |
||
80 | */ |
||
81 | 32 | public function __construct( |
|
109 | |||
110 | /** |
||
111 | * Returns an AST-node for parameter |
||
112 | * |
||
113 | * @return Param |
||
114 | */ |
||
115 | public function getNode() |
||
119 | |||
120 | /** |
||
121 | * Emulating original behaviour of reflection |
||
122 | */ |
||
123 | 1 | public function __debugInfo(): array |
|
129 | |||
130 | /** |
||
131 | * Returns string representation of this parameter. |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | 21 | public function __toString() |
|
165 | |||
166 | /** |
||
167 | * {@inheritDoc} |
||
168 | */ |
||
169 | 22 | public function allowsNull() |
|
183 | |||
184 | /** |
||
185 | * {@inheritDoc} |
||
186 | */ |
||
187 | 3 | public function canBePassedByValue() |
|
191 | |||
192 | /** |
||
193 | * @inheritDoc |
||
194 | */ |
||
195 | 2 | public function getClass() |
|
221 | |||
222 | /** |
||
223 | * {@inheritDoc} |
||
224 | */ |
||
225 | 3 | public function getDeclaringClass() |
|
233 | |||
234 | /** |
||
235 | * {@inheritDoc} |
||
236 | */ |
||
237 | 16 | public function getDeclaringFunction() |
|
241 | |||
242 | /** |
||
243 | * {@inheritDoc} |
||
244 | */ |
||
245 | 13 | public function getDefaultValue() |
|
253 | |||
254 | /** |
||
255 | * {@inheritDoc} |
||
256 | */ |
||
257 | 6 | public function getDefaultValueConstantName() |
|
265 | |||
266 | /** |
||
267 | * @inheritDoc |
||
268 | */ |
||
269 | 22 | public function getName() |
|
273 | |||
274 | /** |
||
275 | * {@inheritDoc} |
||
276 | */ |
||
277 | 3 | public function getPosition() |
|
281 | |||
282 | /** |
||
283 | * @inheritDoc |
||
284 | */ |
||
285 | 22 | public function getType() |
|
307 | |||
308 | /** |
||
309 | * @inheritDoc |
||
310 | */ |
||
311 | 4 | public function hasType() |
|
317 | |||
318 | /** |
||
319 | * @inheritDoc |
||
320 | */ |
||
321 | 3 | public function isArray() |
|
327 | |||
328 | /** |
||
329 | * @inheritDoc |
||
330 | */ |
||
331 | 3 | public function isCallable() |
|
337 | |||
338 | /** |
||
339 | * @inheritDoc |
||
340 | */ |
||
341 | 47 | public function isDefaultValueAvailable() |
|
345 | |||
346 | /** |
||
347 | * {@inheritDoc} |
||
348 | */ |
||
349 | 5 | public function isDefaultValueConstant() |
|
353 | |||
354 | /** |
||
355 | * {@inheritDoc} |
||
356 | */ |
||
357 | 38 | public function isOptional() |
|
361 | |||
362 | /** |
||
363 | * @inheritDoc |
||
364 | */ |
||
365 | 21 | public function isPassedByReference() |
|
369 | |||
370 | /** |
||
371 | * @inheritDoc |
||
372 | */ |
||
373 | 55 | public function isVariadic() |
|
377 | |||
378 | /** |
||
379 | * Returns if all following parameters have a default value definition. |
||
380 | * |
||
381 | * @return bool |
||
382 | * @throws ReflectionException If could not fetch declaring function reflection |
||
383 | */ |
||
384 | 16 | protected function haveSiblingsDefaultValues() |
|
401 | } |
||
402 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.