Complex classes like ReflectionClass 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 ReflectionClass, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 17 | final class ReflectionClass extends AbstractReflectionElement implements ClassReflectionInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var ClassReflectionInterface[] |
||
| 21 | */ |
||
| 22 | private $parentClasses; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var PropertyReflectionInterface[] |
||
| 26 | */ |
||
| 27 | private $properties; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var PropertyReflectionInterface[] |
||
| 31 | */ |
||
| 32 | private $ownProperties; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var ConstantReflectionInterface[] |
||
| 36 | */ |
||
| 37 | private $constants; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var ConstantReflectionInterface[] |
||
| 41 | */ |
||
| 42 | private $ownConstants; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var MethodReflectionInterface[] |
||
| 46 | */ |
||
| 47 | private $methods; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var MethodReflectionInterface[] |
||
| 51 | */ |
||
| 52 | private $ownMethods; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var ClassTraitElementsExtractorInterface |
||
| 56 | */ |
||
| 57 | private $classTraitElementExtractor; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var ParentClassElementsExtractorInterface |
||
| 61 | */ |
||
| 62 | private $parentClassElementExtractor; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param mixed $reflectionClass |
||
| 66 | */ |
||
| 67 | public function __construct($reflectionClass) |
||
| 73 | |||
| 74 | public function getShortName(): string |
||
| 78 | |||
| 79 | public function isAbstract(): bool |
||
| 83 | |||
| 84 | public function isFinal(): bool |
||
| 88 | |||
| 89 | public function isInterface(): bool |
||
| 93 | |||
| 94 | public function isException(): bool |
||
| 98 | |||
| 99 | public function isSubclassOf(string $class): bool |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @return MethodReflectionInterface[] |
||
| 106 | */ |
||
| 107 | public function getMethods(): array |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @return MethodReflectionInterface[] |
||
| 154 | */ |
||
| 155 | public function getOwnMethods(): array |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @return MethodReflectionInterface[] |
||
| 173 | */ |
||
| 174 | public function getTraitMethods(): array |
||
| 178 | |||
| 179 | public function getMethod(string $name): MethodReflectionInterface |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @return PropertyReflectionInterface[] |
||
| 194 | */ |
||
| 195 | public function getProperties(): array |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @return PropertyReflectionInterface[] |
||
| 217 | */ |
||
| 218 | public function getOwnProperties(): array |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @return PropertyReflectionInterface[] |
||
| 236 | */ |
||
| 237 | public function getTraitProperties(): array |
||
| 241 | |||
| 242 | public function getProperty(string $name): PropertyReflectionInterface |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @return ConstantReflectionInterface[] |
||
| 257 | */ |
||
| 258 | public function getConstants(): array |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return ConstantReflectionInterface[] |
||
| 276 | */ |
||
| 277 | public function getOwnConstants(): array |
||
| 291 | |||
| 292 | public function getConstant(string $name): ConstantReflectionInterface |
||
| 304 | |||
| 305 | public function hasConstant(string $name): bool |
||
| 309 | |||
| 310 | public function hasOwnConstant(string $name): bool |
||
| 314 | |||
| 315 | public function getOwnConstant(string $name): ConstantReflectionInterface |
||
| 327 | |||
| 328 | public function getParentClass(): ?ClassReflectionInterface |
||
| 338 | |||
| 339 | public function getParentClassName(): ?string |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @return ClassReflectionInterface[] |
||
| 346 | */ |
||
| 347 | public function getParentClasses(): array |
||
| 357 | |||
| 358 | public function implementsInterface(string $interface): bool |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @return ClassReflectionInterface[] |
||
| 365 | */ |
||
| 366 | public function getInterfaces(): array |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @return ClassReflectionInterface[] |
||
| 375 | */ |
||
| 376 | public function getOwnInterfaces(): array |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @return string[] |
||
| 385 | */ |
||
| 386 | public function getOwnInterfaceNames(): array |
||
| 390 | |||
| 391 | /** |
||
| 392 | * @return ClassReflectionInterface[] |
||
| 393 | */ |
||
| 394 | public function getTraits(): array |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @return string[] |
||
| 407 | */ |
||
| 408 | public function getTraitNames(): array |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @return string[] |
||
| 415 | */ |
||
| 416 | public function getOwnTraitNames(): array |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @return string[] |
||
| 423 | */ |
||
| 424 | public function getTraitAliases(): array |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @return ClassReflectionInterface[] |
||
| 431 | */ |
||
| 432 | public function getOwnTraits(): array |
||
| 442 | |||
| 443 | public function isTrait(): bool |
||
| 447 | |||
| 448 | public function usesTrait(string $trait): bool |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @return ClassReflectionInterface[] |
||
| 455 | */ |
||
| 456 | public function getDirectSubClasses(): array |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @return ClassReflectionInterface[] |
||
| 471 | */ |
||
| 472 | public function getIndirectSubClasses(): array |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @return ClassReflectionInterface[] |
||
| 489 | */ |
||
| 490 | public function getDirectImplementers(): array |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @return ClassReflectionInterface[] |
||
| 501 | */ |
||
| 502 | public function getIndirectImplementers(): array |
||
| 510 | |||
| 511 | /** |
||
| 512 | * @return ClassReflectionInterface[] |
||
| 513 | */ |
||
| 514 | public function getDirectUsers(): array |
||
| 522 | |||
| 523 | /** |
||
| 524 | * @return ClassReflectionInterface[] |
||
| 525 | */ |
||
| 526 | public function getIndirectUsers(): array |
||
| 534 | |||
| 535 | /** |
||
| 536 | * @return MethodReflectionInterface[] |
||
| 537 | */ |
||
| 538 | public function getInheritedMethods(): array |
||
| 542 | |||
| 543 | /** |
||
| 544 | * @return MethodReflectionInterface[] |
||
| 545 | */ |
||
| 546 | public function getUsedMethods(): array |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @return ConstantReflectionInterface[] |
||
| 554 | */ |
||
| 555 | public function getInheritedConstants(): array |
||
| 559 | |||
| 560 | /** |
||
| 561 | * @return PropertyReflectionInterface[] |
||
| 562 | */ |
||
| 563 | public function getInheritedProperties(): array |
||
| 567 | |||
| 568 | /** |
||
| 569 | * @return PropertyReflectionInterface[] |
||
| 570 | */ |
||
| 571 | public function getUsedProperties(): array |
||
| 575 | |||
| 576 | public function hasProperty(string $name): bool |
||
| 584 | |||
| 585 | public function hasMethod(string $name): bool |
||
| 589 | |||
| 590 | public function getVisibilityLevel(): int |
||
| 594 | |||
| 595 | public function getReflectionFactory(): ReflectionFactoryInterface |
||
| 599 | |||
| 600 | /** |
||
| 601 | * @param mixed[] $usedMethods |
||
| 602 | * @return mixed[] |
||
| 603 | */ |
||
| 604 | private function sortUsedMethods(array $usedMethods): array |
||
| 619 | } |
||
| 620 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.