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 |
||
| 24 | class ReflectionParameter extends BaseReflectionParameter |
||
| 25 | { |
||
| 26 | use InternalPropertiesEmulationTrait; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Reflection function or method |
||
| 30 | * |
||
| 31 | * @var \ReflectionFunctionAbstract |
||
| 32 | */ |
||
| 33 | private $declaringFunction; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Stores the default value for node (if present) |
||
| 37 | * |
||
| 38 | * @var mixed |
||
| 39 | */ |
||
| 40 | private $defaultValue = null; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Whether or not default value is constant |
||
| 44 | * |
||
| 45 | * @var bool |
||
| 46 | */ |
||
| 47 | private $isDefaultValueConstant = false; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Name of the constant of default value |
||
| 51 | * |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | private $defaultValueConstantName; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Index of parameter in the list |
||
| 58 | * |
||
| 59 | * @var int |
||
| 60 | */ |
||
| 61 | private $parameterIndex = 0; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Concrete parameter node |
||
| 65 | * |
||
| 66 | * @var Param |
||
| 67 | */ |
||
| 68 | private $parameterNode; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Initializes a reflection for the property |
||
| 72 | * |
||
| 73 | * @param string|array $unusedFunctionName Name of the function/method |
||
| 74 | * @param string $parameterName Name of the parameter to reflect |
||
| 75 | * @param Param $parameterNode Parameter definition node |
||
| 76 | * @param int $parameterIndex Index of parameter |
||
| 77 | * @param \ReflectionFunctionAbstract $declaringFunction |
||
| 78 | */ |
||
| 79 | 32 | public function __construct( |
|
| 107 | |||
| 108 | /** |
||
| 109 | * Returns an AST-node for parameter |
||
| 110 | * |
||
| 111 | * @return Param |
||
| 112 | */ |
||
| 113 | public function getNode() |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Emulating original behaviour of reflection |
||
| 120 | */ |
||
| 121 | 1 | public function ___debugInfo() |
|
| 127 | |||
| 128 | /** |
||
| 129 | * Returns string representation of this parameter. |
||
| 130 | * |
||
| 131 | * @return string |
||
| 132 | */ |
||
| 133 | 21 | public function __toString() |
|
| 163 | |||
| 164 | /** |
||
| 165 | * {@inheritDoc} |
||
| 166 | */ |
||
| 167 | 22 | public function allowsNull() |
|
| 181 | |||
| 182 | /** |
||
| 183 | * {@inheritDoc} |
||
| 184 | */ |
||
| 185 | 3 | public function canBePassedByValue() |
|
| 189 | |||
| 190 | /** |
||
| 191 | * @inheritDoc |
||
| 192 | */ |
||
| 193 | 2 | public function getClass() |
|
| 218 | |||
| 219 | /** |
||
| 220 | * {@inheritDoc} |
||
| 221 | */ |
||
| 222 | 3 | public function getDeclaringClass() |
|
| 230 | |||
| 231 | /** |
||
| 232 | * {@inheritDoc} |
||
| 233 | */ |
||
| 234 | 16 | public function getDeclaringFunction() |
|
| 238 | |||
| 239 | /** |
||
| 240 | * {@inheritDoc} |
||
| 241 | */ |
||
| 242 | 13 | public function getDefaultValue() |
|
| 250 | |||
| 251 | /** |
||
| 252 | * {@inheritDoc} |
||
| 253 | */ |
||
| 254 | 6 | public function getDefaultValueConstantName() |
|
| 262 | |||
| 263 | /** |
||
| 264 | * @inheritDoc |
||
| 265 | */ |
||
| 266 | 22 | public function getName() |
|
| 270 | |||
| 271 | /** |
||
| 272 | * {@inheritDoc} |
||
| 273 | */ |
||
| 274 | 3 | public function getPosition() |
|
| 278 | |||
| 279 | /** |
||
| 280 | * @inheritDoc |
||
| 281 | */ |
||
| 282 | 22 | public function getType() |
|
| 304 | |||
| 305 | /** |
||
| 306 | * @inheritDoc |
||
| 307 | */ |
||
| 308 | 4 | public function hasType() |
|
| 314 | |||
| 315 | /** |
||
| 316 | * @inheritDoc |
||
| 317 | */ |
||
| 318 | 3 | public function isArray() |
|
| 324 | |||
| 325 | /** |
||
| 326 | * @inheritDoc |
||
| 327 | */ |
||
| 328 | 3 | public function isCallable() |
|
| 334 | |||
| 335 | /** |
||
| 336 | * @inheritDoc |
||
| 337 | */ |
||
| 338 | 47 | public function isDefaultValueAvailable() |
|
| 342 | |||
| 343 | /** |
||
| 344 | * {@inheritDoc} |
||
| 345 | */ |
||
| 346 | 5 | public function isDefaultValueConstant() |
|
| 350 | |||
| 351 | /** |
||
| 352 | * {@inheritDoc} |
||
| 353 | */ |
||
| 354 | 38 | public function isOptional() |
|
| 358 | |||
| 359 | /** |
||
| 360 | * @inheritDoc |
||
| 361 | */ |
||
| 362 | 21 | public function isPassedByReference() |
|
| 366 | |||
| 367 | /** |
||
| 368 | * @inheritDoc |
||
| 369 | */ |
||
| 370 | 55 | public function isVariadic() |
|
| 374 | |||
| 375 | /** |
||
| 376 | * Returns if all following parameters have a default value definition. |
||
| 377 | * |
||
| 378 | * @return bool |
||
| 379 | * @throws ReflectionException If could not fetch declaring function reflection |
||
| 380 | */ |
||
| 381 | 16 | protected function haveSiblingsDefalutValues() |
|
| 398 | } |
||
| 399 |