Complex classes like MappingException 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 MappingException, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class MappingException extends \Doctrine\ORM\ORMException |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @return MappingException |
||
| 31 | */ |
||
| 32 | public static function pathRequired() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param string $entityName |
||
| 40 | * |
||
| 41 | * @return MappingException |
||
| 42 | */ |
||
| 43 | 5 | public static function identifierRequired($entityName) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * @param string $entityName |
||
| 61 | * @param string $type |
||
| 62 | * |
||
| 63 | * @return MappingException |
||
| 64 | */ |
||
| 65 | public static function invalidInheritanceType($entityName, $type) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return MappingException |
||
| 72 | */ |
||
| 73 | public static function generatorNotAllowedWithCompositeId() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param string $entity |
||
| 80 | * |
||
| 81 | * @return MappingException |
||
| 82 | */ |
||
| 83 | 1 | public static function missingFieldName($entity) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * @param string $fieldName |
||
| 90 | * |
||
| 91 | * @return MappingException |
||
| 92 | */ |
||
| 93 | public static function missingTargetEntity($fieldName) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param string $fieldName |
||
| 100 | * |
||
| 101 | * @return MappingException |
||
| 102 | */ |
||
| 103 | public static function missingSourceEntity($fieldName) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param string $fieldName |
||
| 110 | * |
||
| 111 | * @return MappingException |
||
| 112 | */ |
||
| 113 | 1 | public static function missingEmbeddedClass($fieldName) |
|
| 117 | |||
| 118 | /** |
||
| 119 | * @param string $entityName |
||
| 120 | * @param string $fileName |
||
| 121 | * |
||
| 122 | * @return MappingException |
||
| 123 | */ |
||
| 124 | public static function mappingFileNotFound($entityName, $fileName) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Exception for invalid property name override. |
||
| 131 | * |
||
| 132 | * @param string $className The entity's name. |
||
| 133 | * @param string $fieldName |
||
| 134 | * |
||
| 135 | * @return MappingException |
||
| 136 | */ |
||
| 137 | 2 | public static function invalidOverrideFieldName($className, $fieldName) |
|
| 141 | |||
| 142 | /** |
||
| 143 | * Exception for invalid property type override. |
||
| 144 | * |
||
| 145 | * @param string $className The entity's name. |
||
| 146 | * @param string $fieldName |
||
| 147 | * |
||
| 148 | * @return MappingException |
||
| 149 | */ |
||
| 150 | 1 | public static function invalidOverrideFieldType($className, $fieldName) |
|
| 154 | |||
| 155 | /** |
||
| 156 | * @param string $className |
||
| 157 | * @param string $fieldName |
||
| 158 | * |
||
| 159 | * @return MappingException |
||
| 160 | */ |
||
| 161 | 1 | public static function mappingNotFound($className, $fieldName) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * @param string $className |
||
| 168 | * @param string $queryName |
||
| 169 | * |
||
| 170 | * @return MappingException |
||
| 171 | */ |
||
| 172 | 1 | public static function queryNotFound($className, $queryName) |
|
| 176 | |||
| 177 | /** |
||
| 178 | * @param string $className |
||
| 179 | * @param string $resultName |
||
| 180 | * |
||
| 181 | * @return MappingException |
||
| 182 | */ |
||
| 183 | public static function resultMappingNotFound($className, $resultName) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param string $entity |
||
| 190 | * @param string $queryName |
||
| 191 | * |
||
| 192 | * @return MappingException |
||
| 193 | */ |
||
| 194 | public static function emptyQueryMapping($entity, $queryName) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @param string $className |
||
| 201 | * |
||
| 202 | * @return MappingException |
||
| 203 | */ |
||
| 204 | 2 | public static function nameIsMandatoryForQueryMapping($className) |
|
| 208 | |||
| 209 | /** |
||
| 210 | * @param string $entity |
||
| 211 | * @param string $queryName |
||
| 212 | * |
||
| 213 | * @return MappingException |
||
| 214 | */ |
||
| 215 | public static function missingQueryMapping($entity, $queryName) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @param string $entity |
||
| 222 | * @param string $resultName |
||
| 223 | * |
||
| 224 | * @return MappingException |
||
| 225 | */ |
||
| 226 | 1 | public static function missingResultSetMappingEntity($entity, $resultName) |
|
| 230 | |||
| 231 | /** |
||
| 232 | * @param string $entity |
||
| 233 | * @param string $resultName |
||
| 234 | * |
||
| 235 | * @return MappingException |
||
| 236 | */ |
||
| 237 | public static function missingResultSetMappingFieldName($entity, $resultName) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @param string $className |
||
| 244 | * |
||
| 245 | * @return MappingException |
||
| 246 | */ |
||
| 247 | public static function nameIsMandatoryForSqlResultSetMapping($className) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @param string $fieldName |
||
| 254 | * |
||
| 255 | * @return MappingException |
||
| 256 | */ |
||
| 257 | public static function oneToManyRequiresMappedBy($fieldName) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @param string $fieldName |
||
| 264 | * |
||
| 265 | * @return MappingException |
||
| 266 | */ |
||
| 267 | public static function joinTableRequired($fieldName) |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Called if a required option was not found but is required |
||
| 274 | * |
||
| 275 | * @param string $field Which field cannot be processed? |
||
| 276 | * @param string $expectedOption Which option is required |
||
| 277 | * @param string $hint Can optionally be used to supply a tip for common mistakes, |
||
| 278 | * e.g. "Did you think of the plural s?" |
||
| 279 | * |
||
| 280 | * @return MappingException |
||
| 281 | */ |
||
| 282 | static function missingRequiredOption($field, $expectedOption, $hint = '') |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Generic exception for invalid mappings. |
||
| 295 | * |
||
| 296 | * @param string $fieldName |
||
| 297 | * |
||
| 298 | * @return MappingException |
||
| 299 | */ |
||
| 300 | public static function invalidMapping($fieldName) |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Exception for reflection exceptions - adds the entity name, |
||
| 307 | * because there might be long classnames that will be shortened |
||
| 308 | * within the stacktrace |
||
| 309 | * |
||
| 310 | * @param string $entity The entity's name |
||
| 311 | * @param \ReflectionException $previousException |
||
| 312 | * |
||
| 313 | * @return MappingException |
||
| 314 | */ |
||
| 315 | public static function reflectionFailure($entity, \ReflectionException $previousException) |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @param string $className |
||
| 322 | * @param string $joinColumn |
||
| 323 | * |
||
| 324 | * @return MappingException |
||
| 325 | */ |
||
| 326 | public static function joinColumnMustPointToMappedField($className, $joinColumn) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @param string $className |
||
| 334 | * |
||
| 335 | * @return MappingException |
||
| 336 | */ |
||
| 337 | 5 | public static function classIsNotAValidEntityOrMappedSuperClass($className) |
|
| 351 | |||
| 352 | /** |
||
| 353 | * @param string $className |
||
| 354 | * @param string $propertyName |
||
| 355 | * |
||
| 356 | * @return MappingException |
||
| 357 | */ |
||
| 358 | public static function propertyTypeIsRequired($className, $propertyName) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @param string $className |
||
| 365 | * |
||
| 366 | * @return MappingException |
||
| 367 | */ |
||
| 368 | public static function tableIdGeneratorNotImplemented($className) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @param string $entity The entity's name. |
||
| 375 | * @param string $fieldName The name of the field that was already declared. |
||
| 376 | * |
||
| 377 | * @return MappingException |
||
| 378 | */ |
||
| 379 | 2 | public static function duplicateFieldMapping($entity, $fieldName) |
|
| 383 | |||
| 384 | /** |
||
| 385 | * @param string $entity |
||
| 386 | * @param string $fieldName |
||
| 387 | * |
||
| 388 | * @return MappingException |
||
| 389 | */ |
||
| 390 | 1 | public static function duplicateAssociationMapping($entity, $fieldName) |
|
| 394 | |||
| 395 | /** |
||
| 396 | * @param string $entity |
||
| 397 | * @param string $queryName |
||
| 398 | * |
||
| 399 | * @return MappingException |
||
| 400 | */ |
||
| 401 | 2 | public static function duplicateQueryMapping($entity, $queryName) |
|
| 405 | |||
| 406 | /** |
||
| 407 | * @param string $entity |
||
| 408 | * @param string $resultName |
||
| 409 | * |
||
| 410 | * @return MappingException |
||
| 411 | */ |
||
| 412 | 1 | public static function duplicateResultSetMapping($entity, $resultName) |
|
| 416 | |||
| 417 | /** |
||
| 418 | * @param string $entity |
||
| 419 | * |
||
| 420 | * @return MappingException |
||
| 421 | */ |
||
| 422 | 1 | public static function singleIdNotAllowedOnCompositePrimaryKey($entity) |
|
| 426 | |||
| 427 | /** |
||
| 428 | * @param string $entity |
||
| 429 | * @param string $fieldName |
||
| 430 | * @param string $unsupportedType |
||
| 431 | * |
||
| 432 | * @return MappingException |
||
| 433 | */ |
||
| 434 | 1 | public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType) |
|
| 440 | |||
| 441 | /** |
||
| 442 | * @param string|null $path |
||
| 443 | * |
||
| 444 | * @return MappingException |
||
| 445 | */ |
||
| 446 | public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null) |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Returns an exception that indicates that a class used in a discriminator map does not exist. |
||
| 460 | * An example would be an outdated (maybe renamed) classname. |
||
| 461 | * |
||
| 462 | * @param string $className The class that could not be found |
||
| 463 | * @param string $owningClass The class that declares the discriminator map. |
||
| 464 | * |
||
| 465 | * @return MappingException |
||
| 466 | */ |
||
| 467 | public static function invalidClassInDiscriminatorMap($className, $owningClass) |
||
| 474 | |||
| 475 | /** |
||
| 476 | * @param string $className |
||
| 477 | * @param array $entries |
||
| 478 | * @param array $map |
||
| 479 | * |
||
| 480 | * @return MappingException |
||
| 481 | */ |
||
| 482 | public static function duplicateDiscriminatorEntry($className, array $entries, array $map) |
||
| 492 | |||
| 493 | /** |
||
| 494 | * @param string $className |
||
| 495 | * |
||
| 496 | * @return MappingException |
||
| 497 | */ |
||
| 498 | public static function missingDiscriminatorMap($className) |
||
| 502 | |||
| 503 | /** |
||
| 504 | * @param string $className |
||
| 505 | * |
||
| 506 | * @return MappingException |
||
| 507 | */ |
||
| 508 | public static function missingDiscriminatorColumn($className) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * @param string $className |
||
| 515 | * @param string $type |
||
| 516 | * |
||
| 517 | * @return MappingException |
||
| 518 | */ |
||
| 519 | public static function invalidDiscriminatorColumnType($className, $type) |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @param string $className |
||
| 526 | * |
||
| 527 | * @return MappingException |
||
| 528 | */ |
||
| 529 | 1 | public static function nameIsMandatoryForDiscriminatorColumns($className) |
|
| 533 | |||
| 534 | /** |
||
| 535 | * @param string $className |
||
| 536 | * @param string $fieldName |
||
| 537 | * |
||
| 538 | * @return MappingException |
||
| 539 | */ |
||
| 540 | public static function cannotVersionIdField($className, $fieldName) |
||
| 544 | |||
| 545 | /** |
||
| 546 | * @param string $className |
||
| 547 | * @param string $fieldName |
||
| 548 | * @param string $type |
||
| 549 | * |
||
| 550 | * @return MappingException |
||
| 551 | */ |
||
| 552 | public static function sqlConversionNotAllowedForIdentifiers($className, $fieldName, $type) |
||
| 556 | |||
| 557 | /** |
||
| 558 | * @param string $className |
||
| 559 | * @param string $columnName |
||
| 560 | * |
||
| 561 | * @return MappingException |
||
| 562 | */ |
||
| 563 | 3 | public static function duplicateColumnName($className, $columnName) |
|
| 567 | |||
| 568 | /** |
||
| 569 | * @param string $className |
||
| 570 | * @param string $field |
||
| 571 | * |
||
| 572 | * @return MappingException |
||
| 573 | */ |
||
| 574 | public static function illegalToManyAssociationOnMappedSuperclass($className, $field) |
||
| 575 | { |
||
| 576 | return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '".$className."#".$field."'."); |
||
| 577 | } |
||
| 578 | |||
| 579 | /** |
||
| 580 | * @param string $className |
||
| 581 | * @param string $targetEntity |
||
| 582 | * @param string $targetField |
||
| 583 | * |
||
| 584 | * @return MappingException |
||
| 585 | */ |
||
| 586 | public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField) |
||
| 591 | |||
| 592 | /** |
||
| 593 | * @param string $className |
||
| 594 | * @param string $field |
||
| 595 | * |
||
| 596 | * @return MappingException |
||
| 597 | */ |
||
| 598 | public static function noSingleAssociationJoinColumnFound($className, $field) |
||
| 602 | |||
| 603 | /** |
||
| 604 | * @param string $className |
||
| 605 | * @param string $column |
||
| 606 | * |
||
| 607 | * @return MappingException |
||
| 608 | */ |
||
| 609 | public static function noFieldNameFoundForColumn($className, $column) |
||
| 614 | |||
| 615 | /** |
||
| 616 | * @param string $className |
||
| 617 | * @param string $field |
||
| 618 | * |
||
| 619 | * @return MappingException |
||
| 620 | */ |
||
| 621 | 1 | public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field) |
|
| 626 | |||
| 627 | /** |
||
| 628 | * @param string $className |
||
| 629 | * @param string $field |
||
| 630 | * |
||
| 631 | * @return MappingException |
||
| 632 | */ |
||
| 633 | 1 | public static function illegalOrphanRemoval($className, $field) |
|
| 638 | |||
| 639 | /** |
||
| 640 | * @param string $className |
||
| 641 | * @param string $field |
||
| 642 | * |
||
| 643 | * @return MappingException |
||
| 644 | */ |
||
| 645 | 2 | public static function illegalInverseIdentifierAssociation($className, $field) |
|
| 649 | |||
| 650 | /** |
||
| 651 | * @param string $className |
||
| 652 | * @param string $field |
||
| 653 | * |
||
| 654 | * @return MappingException |
||
| 655 | */ |
||
| 656 | 3 | public static function illegalToManyIdentifierAssociation($className, $field) |
|
| 660 | |||
| 661 | /** |
||
| 662 | * @param string $className |
||
| 663 | * |
||
| 664 | * @return MappingException |
||
| 665 | */ |
||
| 666 | public static function noInheritanceOnMappedSuperClass($className) |
||
| 667 | { |
||
| 668 | return new self("It is not supported to define inheritance information on a mapped superclass '" . $className . "'."); |
||
| 669 | } |
||
| 670 | |||
| 671 | /** |
||
| 672 | * @param string $className |
||
| 673 | * @param string $rootClassName |
||
| 674 | * |
||
| 675 | * @return MappingException |
||
| 676 | */ |
||
| 677 | public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName) |
||
| 678 | { |
||
| 679 | return new self( |
||
| 680 | "Entity '" . $className . "' has to be part of the discriminator map of '" . $rootClassName . "' " . |
||
| 681 | "to be properly mapped in the inheritance hierarchy. Alternatively you can make '".$className."' an abstract class " . |
||
| 682 | "to avoid this exception from occurring." |
||
| 683 | ); |
||
| 684 | } |
||
| 685 | |||
| 686 | /** |
||
| 687 | * @param string $className |
||
| 688 | * @param string $methodName |
||
| 689 | * |
||
| 690 | * @return MappingException |
||
| 691 | */ |
||
| 692 | 1 | public static function lifecycleCallbackMethodNotFound($className, $methodName) |
|
| 696 | |||
| 697 | /** |
||
| 698 | * @param string $listenerName |
||
| 699 | * @param string $className |
||
| 700 | * |
||
| 701 | * @return \Doctrine\ORM\Mapping\MappingException |
||
| 702 | */ |
||
| 703 | 1 | public static function entityListenerClassNotFound($listenerName, $className) |
|
| 707 | |||
| 708 | /** |
||
| 709 | * @param string $listenerName |
||
| 710 | * @param string $methodName |
||
| 711 | * @param string $className |
||
| 712 | * |
||
| 713 | * @return \Doctrine\ORM\Mapping\MappingException |
||
| 714 | */ |
||
| 715 | 1 | public static function entityListenerMethodNotFound($listenerName, $methodName, $className) |
|
| 719 | |||
| 720 | /** |
||
| 721 | * @param string $listenerName |
||
| 722 | * @param string $methodName |
||
| 723 | * @param string $className |
||
| 724 | * |
||
| 725 | * @return \Doctrine\ORM\Mapping\MappingException |
||
| 726 | */ |
||
| 727 | 1 | public static function duplicateEntityListener($listenerName, $methodName, $className) |
|
| 731 | |||
| 732 | /** |
||
| 733 | * @param string $className |
||
| 734 | * @param string $annotation |
||
| 735 | * |
||
| 736 | * @return MappingException |
||
| 737 | */ |
||
| 738 | public static function invalidFetchMode($className, $annotation) |
||
| 742 | |||
| 743 | /** |
||
| 744 | * @param string $className |
||
| 745 | * |
||
| 746 | * @return MappingException |
||
| 747 | */ |
||
| 748 | public static function compositeKeyAssignedIdGeneratorRequired($className) |
||
| 752 | |||
| 753 | /** |
||
| 754 | * @param string $targetEntity |
||
| 755 | * @param string $sourceEntity |
||
| 756 | * @param string $associationName |
||
| 757 | * |
||
| 758 | * @return MappingException |
||
| 759 | */ |
||
| 760 | 1 | public static function invalidTargetEntityClass($targetEntity, $sourceEntity, $associationName) |
|
| 764 | |||
| 765 | /** |
||
| 766 | * @param array $cascades |
||
| 767 | * @param string $className |
||
| 768 | * @param string $propertyName |
||
| 769 | * |
||
| 770 | * @return MappingException |
||
| 771 | */ |
||
| 772 | public static function invalidCascadeOption(array $cascades, $className, $propertyName) |
||
| 783 | |||
| 784 | /** |
||
| 785 | * @param string $className |
||
| 786 | * |
||
| 787 | * @return MappingException |
||
| 788 | */ |
||
| 789 | 1 | public static function missingSequenceName($className) |
|
| 795 | |||
| 796 | /** |
||
| 797 | * @param string $className |
||
| 798 | * @param string $propertyName |
||
| 799 | * |
||
| 800 | * @return MappingException |
||
| 801 | */ |
||
| 802 | 2 | public static function infiniteEmbeddableNesting($className, $propertyName) |
|
| 813 | } |
||
| 814 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.