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 | * Name of the function or array pair [class name, method name] |
||
| 56 | * |
||
| 57 | * @var string|array |
||
| 58 | */ |
||
| 59 | private $functionName; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Index of parameter in the list |
||
| 63 | * |
||
| 64 | * @var int |
||
| 65 | */ |
||
| 66 | private $parameterIndex = 0; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Concrete parameter node |
||
| 70 | * |
||
| 71 | * @var Param |
||
| 72 | */ |
||
| 73 | private $parameterNode; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Initializes a reflection for the property |
||
| 77 | * |
||
| 78 | * @param string|array $functionName Name of the function/method |
||
| 79 | * @param string $parameterName Name of the parameter to reflect |
||
| 80 | * @param Param $parameterNode Parameter definition node |
||
| 81 | * @param int $parameterIndex Index of parameter |
||
| 82 | * @param \ReflectionFunctionAbstract $declaringFunction |
||
| 83 | */ |
||
| 84 | 9 | public function __construct( |
|
| 113 | |||
| 114 | /** |
||
| 115 | * Emulating original behaviour of reflection |
||
| 116 | */ |
||
| 117 | 1 | public function __debugInfo() |
|
| 123 | |||
| 124 | /** |
||
| 125 | * Returns string representation of this parameter. |
||
| 126 | * |
||
| 127 | * @return string |
||
| 128 | */ |
||
| 129 | 2 | public function __toString() |
|
| 158 | |||
| 159 | /** |
||
| 160 | * {@inheritDoc} |
||
| 161 | */ |
||
| 162 | 1 | public function allowsNull() |
|
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritDoc} |
||
| 174 | */ |
||
| 175 | 1 | public function canBePassedByValue() |
|
| 179 | |||
| 180 | /** |
||
| 181 | * @inheritDoc |
||
| 182 | */ |
||
| 183 | 1 | public function getClass() |
|
| 198 | |||
| 199 | /** |
||
| 200 | * {@inheritDoc} |
||
| 201 | */ |
||
| 202 | 2 | public function getDeclaringClass() |
|
| 210 | |||
| 211 | /** |
||
| 212 | * {@inheritDoc} |
||
| 213 | */ |
||
| 214 | 2 | public function getDeclaringFunction() |
|
| 218 | |||
| 219 | /** |
||
| 220 | * {@inheritDoc} |
||
| 221 | */ |
||
| 222 | 3 | public function getDefaultValue() |
|
| 230 | |||
| 231 | /** |
||
| 232 | * {@inheritDoc} |
||
| 233 | */ |
||
| 234 | 2 | public function getDefaultValueConstantName() |
|
| 242 | |||
| 243 | /** |
||
| 244 | * @inheritDoc |
||
| 245 | */ |
||
| 246 | 2 | public function getName() |
|
| 250 | |||
| 251 | /** |
||
| 252 | * {@inheritDoc} |
||
| 253 | */ |
||
| 254 | 1 | public function getPosition() |
|
| 258 | |||
| 259 | /** |
||
| 260 | * @inheritDoc |
||
| 261 | */ |
||
| 262 | 1 | public function isArray() |
|
| 266 | |||
| 267 | /** |
||
| 268 | * @inheritDoc |
||
| 269 | */ |
||
| 270 | 1 | public function isCallable() |
|
| 274 | |||
| 275 | /** |
||
| 276 | * @inheritDoc |
||
| 277 | */ |
||
| 278 | 9 | public function isDefaultValueAvailable() |
|
| 282 | |||
| 283 | /** |
||
| 284 | * {@inheritDoc} |
||
| 285 | */ |
||
| 286 | 1 | public function isDefaultValueConstant() |
|
| 290 | |||
| 291 | /** |
||
| 292 | * {@inheritDoc} |
||
| 293 | */ |
||
| 294 | 3 | public function isOptional() |
|
| 298 | |||
| 299 | /** |
||
| 300 | * @inheritDoc |
||
| 301 | */ |
||
| 302 | 2 | public function isPassedByReference() |
|
| 306 | |||
| 307 | /** |
||
| 308 | * @inheritDoc |
||
| 309 | */ |
||
| 310 | 2 | public function isVariadic() |
|
| 314 | |||
| 315 | /** |
||
| 316 | * Returns if all following parameters have a default value definition. |
||
| 317 | * |
||
| 318 | * @return bool |
||
| 319 | * @throws ReflectionException If could not fetch declaring function reflection |
||
| 320 | */ |
||
| 321 | 2 | protected function haveSiblingsDefalutValues() |
|
| 338 | } |
||
| 339 |