Complex classes like ReflectionMethod 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 ReflectionMethod, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class ReflectionMethod extends BaseReflectionMethod |
||
| 25 | { |
||
| 26 | use InternalPropertiesEmulationTrait; |
||
| 27 | use ReflectionFunctionLikeTrait; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Name of the class |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | private $className; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Optional declaring class reference |
||
| 38 | * |
||
| 39 | * @var ReflectionClass |
||
| 40 | */ |
||
| 41 | private $declaringClass; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Initializes reflection instance for the method node |
||
| 45 | * |
||
| 46 | * @param string $className Name of the class |
||
| 47 | * @param string $methodName Name of the method |
||
| 48 | 43 | * @param ?ClassMethod $classMethodNode AST-node for method |
|
|
|
|||
| 49 | * @param ?ReflectionClass $declaringClass Optional declaring class |
||
| 50 | */ |
||
| 51 | public function __construct( |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Returns an AST-node for method |
||
| 68 | */ |
||
| 69 | public function getNode(): ClassMethod |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Emulating original behaviour of reflection |
||
| 76 | 1 | */ |
|
| 77 | public function __debugInfo(): array |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Returns the string representation of the Reflection method object. |
||
| 87 | * |
||
| 88 | * @link http://php.net/manual/en/reflectionmethod.tostring.php |
||
| 89 | * |
||
| 90 | * @return string |
||
| 91 | 64 | */ |
|
| 92 | public function __toString() |
||
| 138 | |||
| 139 | /** |
||
| 140 | * {@inheritDoc} |
||
| 141 | 1 | */ |
|
| 142 | public function getClosure($object = null) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * {@inheritDoc} |
||
| 151 | 135 | */ |
|
| 152 | public function getDeclaringClass() |
||
| 156 | |||
| 157 | /** |
||
| 158 | * {@inheritDoc} |
||
| 159 | 65 | */ |
|
| 160 | public function getModifiers() |
||
| 184 | |||
| 185 | /** |
||
| 186 | * {@inheritDoc} |
||
| 187 | 65 | */ |
|
| 188 | public function getPrototype() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * {@inheritDoc} |
||
| 205 | 1 | */ |
|
| 206 | public function invoke($object, $args = null) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * {@inheritDoc} |
||
| 215 | 3 | */ |
|
| 216 | public function invokeArgs($object, array $args) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * {@inheritDoc} |
||
| 225 | 129 | */ |
|
| 226 | public function isAbstract() |
||
| 230 | |||
| 231 | /** |
||
| 232 | * {@inheritDoc} |
||
| 233 | 128 | */ |
|
| 234 | public function isConstructor() |
||
| 238 | |||
| 239 | /** |
||
| 240 | * {@inheritDoc} |
||
| 241 | 128 | */ |
|
| 242 | public function isDestructor() |
||
| 246 | |||
| 247 | /** |
||
| 248 | * {@inheritDoc} |
||
| 249 | 129 | */ |
|
| 250 | public function isFinal() |
||
| 254 | |||
| 255 | /** |
||
| 256 | * {@inheritDoc} |
||
| 257 | 129 | */ |
|
| 258 | public function isPrivate() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * {@inheritDoc} |
||
| 265 | 129 | */ |
|
| 266 | public function isProtected() |
||
| 270 | |||
| 271 | /** |
||
| 272 | * {@inheritDoc} |
||
| 273 | 132 | */ |
|
| 274 | public function isPublic() |
||
| 278 | |||
| 279 | /** |
||
| 280 | * {@inheritDoc} |
||
| 281 | 129 | */ |
|
| 282 | public function isStatic() |
||
| 286 | |||
| 287 | /** |
||
| 288 | * {@inheritDoc} |
||
| 289 | 1 | */ |
|
| 290 | public function setAccessible($accessible) |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Parses methods from the concrete class node |
||
| 299 | * |
||
| 300 | * @param ClassLike $classLikeNode Class-like node |
||
| 301 | * @param ReflectionClass $reflectionClass Reflection of the class |
||
| 302 | * |
||
| 303 | * @return ReflectionMethod[] |
||
| 304 | 56 | */ |
|
| 305 | public static function collectFromClassNode(ClassLike $classLikeNode, ReflectionClass $reflectionClass): array |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Implementation of internal reflection initialization |
||
| 328 | */ |
||
| 329 | protected function __initialize(): void |
||
| 333 | 69 | ||
| 334 | /** |
||
| 335 | * Returns ClassMethod node to prevent all possible type checks with instanceof |
||
| 336 | */ |
||
| 337 | private function getClassMethodNode(): ClassMethod |
||
| 341 | } |
||
| 342 |
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.