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 | 32 | public function __construct( |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Returns an AST-node for parameter |
||
| 109 | * |
||
| 110 | * @return Param |
||
| 111 | */ |
||
| 112 | public function getNode() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Emulating original behaviour of reflection |
||
| 119 | */ |
||
| 120 | 1 | public function ___debugInfo() |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Returns string representation of this parameter. |
||
| 129 | * |
||
| 130 | * @return string |
||
| 131 | */ |
||
| 132 | 21 | public function __toString() |
|
| 162 | |||
| 163 | /** |
||
| 164 | * {@inheritDoc} |
||
| 165 | */ |
||
| 166 | 22 | public function allowsNull() |
|
| 180 | |||
| 181 | /** |
||
| 182 | * {@inheritDoc} |
||
| 183 | */ |
||
| 184 | 3 | public function canBePassedByValue() |
|
| 188 | |||
| 189 | /** |
||
| 190 | * @inheritDoc |
||
| 191 | */ |
||
| 192 | 2 | public function getClass() |
|
| 217 | |||
| 218 | /** |
||
| 219 | * {@inheritDoc} |
||
| 220 | */ |
||
| 221 | 3 | public function getDeclaringClass() |
|
| 229 | |||
| 230 | /** |
||
| 231 | * {@inheritDoc} |
||
| 232 | */ |
||
| 233 | 16 | public function getDeclaringFunction() |
|
| 237 | |||
| 238 | /** |
||
| 239 | * {@inheritDoc} |
||
| 240 | */ |
||
| 241 | 13 | public function getDefaultValue() |
|
| 249 | |||
| 250 | /** |
||
| 251 | * {@inheritDoc} |
||
| 252 | */ |
||
| 253 | 6 | public function getDefaultValueConstantName() |
|
| 261 | |||
| 262 | /** |
||
| 263 | * @inheritDoc |
||
| 264 | */ |
||
| 265 | 22 | public function getName() |
|
| 269 | |||
| 270 | /** |
||
| 271 | * {@inheritDoc} |
||
| 272 | */ |
||
| 273 | 3 | public function getPosition() |
|
| 277 | |||
| 278 | /** |
||
| 279 | * @inheritDoc |
||
| 280 | */ |
||
| 281 | 22 | public function getType() |
|
| 300 | |||
| 301 | /** |
||
| 302 | * @inheritDoc |
||
| 303 | */ |
||
| 304 | 4 | public function hasType() |
|
| 310 | |||
| 311 | /** |
||
| 312 | * @inheritDoc |
||
| 313 | */ |
||
| 314 | 3 | public function isArray() |
|
| 318 | |||
| 319 | /** |
||
| 320 | * @inheritDoc |
||
| 321 | */ |
||
| 322 | 3 | public function isCallable() |
|
| 326 | |||
| 327 | /** |
||
| 328 | * @inheritDoc |
||
| 329 | */ |
||
| 330 | 47 | public function isDefaultValueAvailable() |
|
| 334 | |||
| 335 | /** |
||
| 336 | * {@inheritDoc} |
||
| 337 | */ |
||
| 338 | 5 | public function isDefaultValueConstant() |
|
| 342 | |||
| 343 | /** |
||
| 344 | * {@inheritDoc} |
||
| 345 | */ |
||
| 346 | 38 | public function isOptional() |
|
| 350 | |||
| 351 | /** |
||
| 352 | * @inheritDoc |
||
| 353 | */ |
||
| 354 | 21 | public function isPassedByReference() |
|
| 358 | |||
| 359 | /** |
||
| 360 | * @inheritDoc |
||
| 361 | */ |
||
| 362 | 55 | public function isVariadic() |
|
| 366 | |||
| 367 | /** |
||
| 368 | * Returns if all following parameters have a default value definition. |
||
| 369 | * |
||
| 370 | * @return bool |
||
| 371 | * @throws ReflectionException If could not fetch declaring function reflection |
||
| 372 | */ |
||
| 373 | 16 | protected function haveSiblingsDefalutValues() |
|
| 390 | } |
||
| 391 |