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 | 6 | 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 | * |
||
| 430 | * @return MappingException |
||
| 431 | */ |
||
| 432 | 1 | public static function noIdDefined($entity) |
|
| 436 | |||
| 437 | /** |
||
| 438 | * @param string $entity |
||
| 439 | * @param string $fieldName |
||
| 440 | * @param string $unsupportedType |
||
| 441 | * |
||
| 442 | * @return MappingException |
||
| 443 | */ |
||
| 444 | 1 | public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType) |
|
| 450 | |||
| 451 | /** |
||
| 452 | * @param string|null $path |
||
| 453 | * |
||
| 454 | * @return MappingException |
||
| 455 | */ |
||
| 456 | public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null) |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Returns an exception that indicates that a class used in a discriminator map does not exist. |
||
| 470 | * An example would be an outdated (maybe renamed) classname. |
||
| 471 | * |
||
| 472 | * @param string $className The class that could not be found |
||
| 473 | * @param string $owningClass The class that declares the discriminator map. |
||
| 474 | * |
||
| 475 | * @return MappingException |
||
| 476 | */ |
||
| 477 | public static function invalidClassInDiscriminatorMap($className, $owningClass) |
||
| 484 | |||
| 485 | /** |
||
| 486 | * @param string $className |
||
| 487 | * @param array $entries |
||
| 488 | * @param array $map |
||
| 489 | * |
||
| 490 | * @return MappingException |
||
| 491 | */ |
||
| 492 | public static function duplicateDiscriminatorEntry($className, array $entries, array $map) |
||
| 502 | |||
| 503 | /** |
||
| 504 | * @param string $className |
||
| 505 | * |
||
| 506 | * @return MappingException |
||
| 507 | */ |
||
| 508 | public static function missingDiscriminatorMap($className) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * @param string $className |
||
| 515 | * |
||
| 516 | * @return MappingException |
||
| 517 | */ |
||
| 518 | public static function missingDiscriminatorColumn($className) |
||
| 522 | |||
| 523 | /** |
||
| 524 | * @param string $className |
||
| 525 | * @param string $type |
||
| 526 | * |
||
| 527 | * @return MappingException |
||
| 528 | */ |
||
| 529 | public static function invalidDiscriminatorColumnType($className, $type) |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @param string $className |
||
| 536 | * |
||
| 537 | * @return MappingException |
||
| 538 | */ |
||
| 539 | 1 | public static function nameIsMandatoryForDiscriminatorColumns($className) |
|
| 543 | |||
| 544 | /** |
||
| 545 | * @param string $className |
||
| 546 | * @param string $fieldName |
||
| 547 | * |
||
| 548 | * @return MappingException |
||
| 549 | */ |
||
| 550 | public static function cannotVersionIdField($className, $fieldName) |
||
| 554 | |||
| 555 | /** |
||
| 556 | * @param string $className |
||
| 557 | * @param string $fieldName |
||
| 558 | * @param string $type |
||
| 559 | * |
||
| 560 | * @return MappingException |
||
| 561 | */ |
||
| 562 | public static function sqlConversionNotAllowedForIdentifiers($className, $fieldName, $type) |
||
| 566 | |||
| 567 | /** |
||
| 568 | * @param string $className |
||
| 569 | * @param string $columnName |
||
| 570 | * |
||
| 571 | * @return MappingException |
||
| 572 | */ |
||
| 573 | 3 | public static function duplicateColumnName($className, $columnName) |
|
| 577 | |||
| 578 | /** |
||
| 579 | * @param string $className |
||
| 580 | * @param string $field |
||
| 581 | * |
||
| 582 | * @return MappingException |
||
| 583 | */ |
||
| 584 | 1 | public static function illegalToManyAssociationOnMappedSuperclass($className, $field) |
|
| 588 | |||
| 589 | /** |
||
| 590 | * @param string $className |
||
| 591 | * @param string $targetEntity |
||
| 592 | * @param string $targetField |
||
| 593 | * |
||
| 594 | * @return MappingException |
||
| 595 | */ |
||
| 596 | public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField) |
||
| 601 | |||
| 602 | /** |
||
| 603 | * @param string $className |
||
| 604 | * @param string $field |
||
| 605 | * |
||
| 606 | * @return MappingException |
||
| 607 | */ |
||
| 608 | public static function noSingleAssociationJoinColumnFound($className, $field) |
||
| 612 | |||
| 613 | /** |
||
| 614 | * @param string $className |
||
| 615 | * @param string $column |
||
| 616 | * |
||
| 617 | * @return MappingException |
||
| 618 | */ |
||
| 619 | public static function noFieldNameFoundForColumn($className, $column) |
||
| 624 | |||
| 625 | /** |
||
| 626 | * @param string $className |
||
| 627 | * @param string $field |
||
| 628 | * |
||
| 629 | * @return MappingException |
||
| 630 | */ |
||
| 631 | 1 | public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field) |
|
| 636 | |||
| 637 | /** |
||
| 638 | * @param string $className |
||
| 639 | * @param string $field |
||
| 640 | * |
||
| 641 | * @return MappingException |
||
| 642 | */ |
||
| 643 | 1 | public static function illegalOrphanRemoval($className, $field) |
|
| 648 | |||
| 649 | /** |
||
| 650 | * @param string $className |
||
| 651 | * @param string $field |
||
| 652 | * |
||
| 653 | * @return MappingException |
||
| 654 | */ |
||
| 655 | 2 | public static function illegalInverseIdentifierAssociation($className, $field) |
|
| 659 | |||
| 660 | /** |
||
| 661 | * @param string $className |
||
| 662 | * @param string $field |
||
| 663 | * |
||
| 664 | * @return MappingException |
||
| 665 | */ |
||
| 666 | 3 | public static function illegalToManyIdentifierAssociation($className, $field) |
|
| 670 | |||
| 671 | /** |
||
| 672 | * @param string $className |
||
| 673 | * |
||
| 674 | * @return MappingException |
||
| 675 | */ |
||
| 676 | 1 | public static function noInheritanceOnMappedSuperClass($className) |
|
| 680 | |||
| 681 | /** |
||
| 682 | * @param string $className |
||
| 683 | * @param string $rootClassName |
||
| 684 | * |
||
| 685 | * @return MappingException |
||
| 686 | */ |
||
| 687 | 1 | public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName) |
|
| 695 | |||
| 696 | /** |
||
| 697 | * @param string $className |
||
| 698 | * @param string $methodName |
||
| 699 | * |
||
| 700 | * @return MappingException |
||
| 701 | */ |
||
| 702 | 1 | public static function lifecycleCallbackMethodNotFound($className, $methodName) |
|
| 706 | |||
| 707 | /** |
||
| 708 | * @param string $listenerName |
||
| 709 | * @param string $className |
||
| 710 | * |
||
| 711 | * @return \Doctrine\ORM\Mapping\MappingException |
||
| 712 | */ |
||
| 713 | 1 | public static function entityListenerClassNotFound($listenerName, $className) |
|
| 717 | |||
| 718 | /** |
||
| 719 | * @param string $listenerName |
||
| 720 | * @param string $methodName |
||
| 721 | * @param string $className |
||
| 722 | * |
||
| 723 | * @return \Doctrine\ORM\Mapping\MappingException |
||
| 724 | */ |
||
| 725 | 1 | public static function entityListenerMethodNotFound($listenerName, $methodName, $className) |
|
| 729 | |||
| 730 | /** |
||
| 731 | * @param string $listenerName |
||
| 732 | * @param string $methodName |
||
| 733 | * @param string $className |
||
| 734 | * |
||
| 735 | * @return \Doctrine\ORM\Mapping\MappingException |
||
| 736 | */ |
||
| 737 | 1 | public static function duplicateEntityListener($listenerName, $methodName, $className) |
|
| 741 | |||
| 742 | /** |
||
| 743 | * @param string $className |
||
| 744 | * @param string $annotation |
||
| 745 | * |
||
| 746 | * @return MappingException |
||
| 747 | */ |
||
| 748 | public static function invalidFetchMode($className, $annotation) |
||
| 752 | |||
| 753 | /** |
||
| 754 | * @param string $className |
||
| 755 | * |
||
| 756 | * @return MappingException |
||
| 757 | */ |
||
| 758 | public static function compositeKeyAssignedIdGeneratorRequired($className) |
||
| 762 | |||
| 763 | /** |
||
| 764 | * @param string $targetEntity |
||
| 765 | * @param string $sourceEntity |
||
| 766 | * @param string $associationName |
||
| 767 | * |
||
| 768 | * @return MappingException |
||
| 769 | */ |
||
| 770 | 1 | public static function invalidTargetEntityClass($targetEntity, $sourceEntity, $associationName) |
|
| 774 | |||
| 775 | /** |
||
| 776 | * @param array $cascades |
||
| 777 | * @param string $className |
||
| 778 | * @param string $propertyName |
||
| 779 | * |
||
| 780 | * @return MappingException |
||
| 781 | */ |
||
| 782 | public static function invalidCascadeOption(array $cascades, $className, $propertyName) |
||
| 793 | |||
| 794 | /** |
||
| 795 | * @param string $className |
||
| 796 | * |
||
| 797 | * @return MappingException |
||
| 798 | */ |
||
| 799 | 1 | public static function missingSequenceName($className) |
|
| 805 | |||
| 806 | /** |
||
| 807 | * @param string $className |
||
| 808 | * @param string $propertyName |
||
| 809 | * |
||
| 810 | * @return MappingException |
||
| 811 | */ |
||
| 812 | 2 | public static function infiniteEmbeddableNesting($className, $propertyName) |
|
| 823 | } |
||
| 824 |
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.