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 | 32 | * @param ?ReflectionFunctionAbstract $declaringFunction |
|
| 80 | */ |
||
| 81 | public function __construct( |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Returns an AST-node for parameter |
||
| 112 | * |
||
| 113 | * @return Param |
||
| 114 | */ |
||
| 115 | public function getNode() |
||
| 119 | |||
| 120 | /** |
||
| 121 | 1 | * Emulating original behaviour of reflection |
|
| 122 | */ |
||
| 123 | public function __debugInfo(): array |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Returns string representation of this parameter. |
||
| 132 | * |
||
| 133 | 21 | * @return string |
|
| 134 | */ |
||
| 135 | 21 | public function __toString() |
|
| 165 | |||
| 166 | /** |
||
| 167 | 22 | * {@inheritDoc} |
|
| 168 | */ |
||
| 169 | public function allowsNull() |
||
| 183 | |||
| 184 | /** |
||
| 185 | 3 | * {@inheritDoc} |
|
| 186 | */ |
||
| 187 | 3 | public function canBePassedByValue() |
|
| 191 | |||
| 192 | /** |
||
| 193 | 2 | * @inheritDoc |
|
| 194 | */ |
||
| 195 | 2 | public function getClass() |
|
| 221 | |||
| 222 | 3 | /** |
|
| 223 | * {@inheritDoc} |
||
| 224 | 3 | */ |
|
| 225 | 2 | public function getDeclaringClass() |
|
| 233 | |||
| 234 | 16 | /** |
|
| 235 | * {@inheritDoc} |
||
| 236 | 16 | */ |
|
| 237 | public function getDeclaringFunction() |
||
| 241 | |||
| 242 | 13 | /** |
|
| 243 | * {@inheritDoc} |
||
| 244 | 13 | */ |
|
| 245 | 1 | public function getDefaultValue() |
|
| 253 | |||
| 254 | 6 | /** |
|
| 255 | * {@inheritDoc} |
||
| 256 | 6 | */ |
|
| 257 | 1 | public function getDefaultValueConstantName() |
|
| 265 | |||
| 266 | 22 | /** |
|
| 267 | * @inheritDoc |
||
| 268 | 22 | */ |
|
| 269 | public function getName() |
||
| 273 | |||
| 274 | 3 | /** |
|
| 275 | * {@inheritDoc} |
||
| 276 | 3 | */ |
|
| 277 | public function getPosition() |
||
| 281 | |||
| 282 | 22 | /** |
|
| 283 | * @inheritDoc |
||
| 284 | 22 | */ |
|
| 285 | 22 | public function getType() |
|
| 307 | |||
| 308 | 4 | /** |
|
| 309 | * @inheritDoc |
||
| 310 | 4 | */ |
|
| 311 | public function hasType() |
||
| 317 | |||
| 318 | 3 | /** |
|
| 319 | * @inheritDoc |
||
| 320 | 3 | */ |
|
| 321 | public function isArray() |
||
| 327 | |||
| 328 | 3 | /** |
|
| 329 | * @inheritDoc |
||
| 330 | 3 | */ |
|
| 331 | public function isCallable() |
||
| 337 | |||
| 338 | 47 | /** |
|
| 339 | * @inheritDoc |
||
| 340 | 47 | */ |
|
| 341 | public function isDefaultValueAvailable() |
||
| 345 | |||
| 346 | 5 | /** |
|
| 347 | * {@inheritDoc} |
||
| 348 | 5 | */ |
|
| 349 | public function isDefaultValueConstant() |
||
| 353 | |||
| 354 | 38 | /** |
|
| 355 | * {@inheritDoc} |
||
| 356 | 38 | */ |
|
| 357 | public function isOptional() |
||
| 361 | |||
| 362 | 21 | /** |
|
| 363 | * @inheritDoc |
||
| 364 | 21 | */ |
|
| 365 | public function isPassedByReference() |
||
| 369 | |||
| 370 | 55 | /** |
|
| 371 | * @inheritDoc |
||
| 372 | 55 | */ |
|
| 373 | public function isVariadic() |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Returns if all following parameters have a default value definition. |
||
| 380 | * |
||
| 381 | 16 | * @return bool |
|
| 382 | * @throws ReflectionException If could not fetch declaring function reflection |
||
| 383 | 16 | */ |
|
| 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.