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 |
||
22 | class MappingException extends BaseMappingException |
||
23 | { |
||
24 | 68 | public function __construct($message = '', $code = 0, ?Throwable $previous = null) |
|
31 | |||
32 | public static function typeExists(string $name) : self |
||
36 | |||
37 | public static function typeNotFound(string $name) : self |
||
41 | |||
42 | 6 | public static function mappingNotFound(string $className, string $fieldName) : self |
|
46 | |||
47 | public static function referenceMappingNotFound(string $className, string $fieldName) : self |
||
51 | |||
52 | 2 | public static function mappingNotFoundInClassNorDescendants(string $className, string $fieldName) : self |
|
56 | |||
57 | 2 | public static function referenceFieldConflict(string $fieldName, string $className, string $className2) : self |
|
61 | |||
62 | 2 | public static function mappingNotFoundByDbName(string $className, string $dbFieldName) : self |
|
66 | |||
67 | public static function duplicateFieldMapping(string $document, string $fieldName) : self |
||
71 | |||
72 | 2 | public static function duplicateDatabaseFieldName(string $document, string $offendingFieldName, string $databaseName, string $originalFieldName) : self |
|
76 | |||
77 | 2 | public static function discriminatorFieldConflict(string $document, string $fieldName) : self |
|
81 | |||
82 | public static function invalidClassInDiscriminatorMap(string $className, string $owningClass) : self |
||
86 | |||
87 | 14 | public static function unlistedClassInDiscriminatorMap(string $className) : self |
|
91 | |||
92 | public static function invalidDiscriminatorValue(string $value, string $owningClass) : self |
||
96 | |||
97 | public static function missingFieldName(string $className) : self |
||
101 | |||
102 | 5 | public static function classIsNotAValidDocument(string $className) : self |
|
106 | |||
107 | 5 | public static function classCanOnlyBeMappedByOneAbstractDocument(string $className, AbstractDocument $mappedAs, AbstractDocument $offending) : self |
|
116 | |||
117 | public static function reflectionFailure(string $document, ReflectionException $previousException) : self |
||
121 | |||
122 | public static function identifierRequired(string $documentName) : self |
||
126 | |||
127 | public static function missingIdentifierField(string $className, string $fieldName) : self |
||
131 | |||
132 | public static function missingIdGeneratorClass(string $className) : self |
||
136 | |||
137 | public static function classIsNotAValidGenerator(string $className) : self |
||
141 | |||
142 | public static function missingGeneratorSetter(string $className, string $optionName) : self |
||
146 | |||
147 | 1 | public static function cascadeOnEmbeddedNotAllowed(string $className, string $fieldName) : self |
|
151 | |||
152 | 3 | public static function simpleReferenceRequiresTargetDocument(string $className, string $fieldName) : self |
|
156 | |||
157 | 1 | public static function simpleReferenceMustNotTargetDiscriminatedDocument(string $targetDocument) : self |
|
161 | |||
162 | 1 | public static function atomicCollectionStrategyNotAllowed(string $strategy, string $className, string $fieldName) : self |
|
166 | |||
167 | 4 | public static function owningAndInverseReferencesRequireTargetDocument(string $className, string $fieldName) : self |
|
171 | |||
172 | 1 | public static function mustNotChangeIdentifierFieldsType(string $className, string $fieldName) : self |
|
176 | |||
177 | 1 | public static function referenceManySortMustNotBeUsedWithNonSetCollectionStrategy(string $className, string $fieldName, string $strategy) : self |
|
181 | |||
182 | public static function invalidStorageStrategy(string $className, string $fieldName, string $type, string $strategy) : self |
||
186 | |||
187 | 1 | public static function collectionClassDoesNotImplementCommonInterface(string $className, string $fieldName, string $collectionClass) : self |
|
191 | |||
192 | 2 | public static function shardKeyInSingleCollInheritanceSubclass(string $subclassName) : self |
|
196 | |||
197 | 2 | public static function embeddedDocumentCantHaveShardKey(string $className) : self |
|
201 | |||
202 | 1 | public static function onlySetStrategyAllowedInShardKey(string $className, string $fieldName) : self |
|
206 | |||
207 | 3 | public static function noMultiKeyShardKeys(string $className, string $fieldName) : self |
|
211 | |||
212 | public static function cannotLookupDbRefReference(string $className, string $fieldName) : self |
||
216 | |||
217 | public static function repositoryMethodLookupNotAllowed(string $className, string $fieldName) : self |
||
221 | |||
222 | 1 | public static function cannotUseShardedCollectionInOutStage(string $className) : self |
|
226 | |||
227 | 3 | public static function cannotUseShardedCollectionInLookupStages(string $className) : self |
|
231 | |||
232 | public static function referencePrimersOnlySupportedForInverseReferenceMany(string $className, string $fieldName) : self |
||
236 | |||
237 | 1 | public static function connectFromFieldMustReferenceSameDocument(string $fieldName) : self |
|
241 | |||
242 | 3 | public static function repositoryMethodCanNotBeCombinedWithSkipLimitAndSort(string $className, string $fieldName) : self |
|
246 | |||
247 | 2 | public static function xmlMappingFileInvalid(string $filename, string $errorDetails) : self |
|
251 | |||
252 | 1 | public static function fieldNotAllowedForGridFS(string $className, string $fieldName) : self |
|
256 | |||
257 | public static function discriminatorNotAllowedForGridFS(string $className) : self |
||
261 | } |
||
262 |
If you suppress an error, we recommend checking for the error condition explicitly: