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 |
||
| 15 | class MappingException extends BaseMappingException |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @param string $name |
||
| 19 | * @return MappingException |
||
| 20 | */ |
||
| 21 | public static function typeExists($name) |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param string $name |
||
| 28 | * @return MappingException |
||
| 29 | */ |
||
| 30 | public static function typeNotFound($name) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $className |
||
| 37 | * @param string $fieldName |
||
| 38 | * @return MappingException |
||
| 39 | */ |
||
| 40 | 6 | public static function mappingNotFound($className, $fieldName) |
|
| 44 | |||
| 45 | /** |
||
| 46 | * @param string $className |
||
| 47 | * @param string $fieldName |
||
| 48 | * @return MappingException |
||
| 49 | */ |
||
| 50 | public static function referenceMappingNotFound($className, $fieldName) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $className |
||
| 57 | * @param string $fieldName |
||
| 58 | * @return MappingException |
||
| 59 | */ |
||
| 60 | 2 | public static function mappingNotFoundInClassNorDescendants($className, $fieldName) |
|
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $fieldName |
||
| 67 | * @param string $className |
||
| 68 | * @param string $className2 |
||
| 69 | * @return MappingException |
||
| 70 | */ |
||
| 71 | 2 | public static function referenceFieldConflict($fieldName, $className, $className2) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * @param string $className |
||
| 78 | * @param string $dbFieldName |
||
| 79 | * @return MappingException |
||
| 80 | */ |
||
| 81 | 1 | public static function mappingNotFoundByDbName($className, $dbFieldName) |
|
| 82 | { |
||
| 83 | 1 | return new self(sprintf("No mapping found for field by DB name '%s' in class '%s'.", $dbFieldName, $className)); |
|
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param string $document |
||
| 88 | * @param string $fieldName |
||
| 89 | * @return MappingException |
||
| 90 | */ |
||
| 91 | public static function duplicateFieldMapping($document, $fieldName) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @param string $document |
||
| 98 | * @param string $fieldName |
||
| 99 | * @return MappingException |
||
| 100 | */ |
||
| 101 | 2 | public static function discriminatorFieldConflict($document, $fieldName) |
|
| 105 | |||
| 106 | /** |
||
| 107 | * Throws an exception that indicates that a class used in a discriminator map does not exist. |
||
| 108 | * An example would be an outdated (maybe renamed) classname. |
||
| 109 | * |
||
| 110 | * @param string $className The class that could not be found |
||
| 111 | * @param string $owningClass The class that declares the discriminator map. |
||
| 112 | * @return MappingException |
||
| 113 | */ |
||
| 114 | public static function invalidClassInDiscriminatorMap($className, $owningClass) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Throws an exception that indicates a discriminator value does not exist in a map |
||
| 121 | * |
||
| 122 | * @param string $value The discriminator value that could not be found |
||
| 123 | * @param string $owningClass The class that declares the discriminator map |
||
| 124 | * @return MappingException |
||
| 125 | */ |
||
| 126 | public static function invalidDiscriminatorValue($value, $owningClass) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @param string $className |
||
| 133 | * @return MappingException |
||
| 134 | */ |
||
| 135 | public static function missingFieldName($className) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @param string $className |
||
| 142 | * @return MappingException |
||
| 143 | */ |
||
| 144 | 3 | public static function classIsNotAValidDocument($className) |
|
| 148 | |||
| 149 | /** |
||
| 150 | * Exception for reflection exceptions - adds the document name, |
||
| 151 | * because there might be long classnames that will be shortened |
||
| 152 | * within the stacktrace |
||
| 153 | * |
||
| 154 | * @param string $document The document's name |
||
| 155 | * @return \Doctrine\ODM\MongoDB\Mapping\MappingException |
||
| 156 | */ |
||
| 157 | public static function reflectionFailure($document, \ReflectionException $previousException) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @param string $documentName |
||
| 164 | * @return MappingException |
||
| 165 | */ |
||
| 166 | public static function identifierRequired($documentName) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @param string $className |
||
| 173 | * @param string $fieldName |
||
| 174 | * @return MappingException |
||
| 175 | */ |
||
| 176 | public static function missingIdentifierField($className, $fieldName) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @param string $className |
||
| 183 | * @return MappingException |
||
| 184 | */ |
||
| 185 | public static function missingIdGeneratorClass($className) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @param string $className |
||
| 192 | * @return MappingException |
||
| 193 | */ |
||
| 194 | public static function classIsNotAValidGenerator($className) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @param string $className |
||
| 201 | * @param string $optionName |
||
| 202 | * @return MappingException |
||
| 203 | */ |
||
| 204 | public static function missingGeneratorSetter($className, $optionName) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @param string $className |
||
| 211 | * @param string $fieldName |
||
| 212 | * @return MappingException |
||
| 213 | */ |
||
| 214 | 1 | public static function cascadeOnEmbeddedNotAllowed($className, $fieldName) |
|
| 218 | |||
| 219 | /** |
||
| 220 | * @param string $className |
||
| 221 | * @param string $fieldName |
||
| 222 | * @return MappingException |
||
| 223 | */ |
||
| 224 | 3 | public static function simpleReferenceRequiresTargetDocument($className, $fieldName) |
|
| 228 | |||
| 229 | /** |
||
| 230 | * @param string $targetDocument |
||
| 231 | * @return MappingException |
||
| 232 | */ |
||
| 233 | 1 | public static function simpleReferenceMustNotTargetDiscriminatedDocument($targetDocument) |
|
| 237 | |||
| 238 | /** |
||
| 239 | * @param string $strategy |
||
| 240 | * @param string $className |
||
| 241 | * @param string $fieldName |
||
| 242 | * @return MappingException |
||
| 243 | */ |
||
| 244 | 1 | public static function atomicCollectionStrategyNotAllowed($strategy, $className, $fieldName) |
|
| 248 | |||
| 249 | /** |
||
| 250 | * @param string $className |
||
| 251 | * @param string $fieldName |
||
| 252 | * @return MappingException |
||
| 253 | */ |
||
| 254 | 4 | public static function owningAndInverseReferencesRequireTargetDocument($className, $fieldName) |
|
| 258 | |||
| 259 | /** |
||
| 260 | * @param string $className |
||
| 261 | * @param string $fieldName |
||
| 262 | * @return MappingException |
||
| 263 | */ |
||
| 264 | 1 | public static function mustNotChangeIdentifierFieldsType($className, $fieldName) |
|
| 268 | |||
| 269 | /** |
||
| 270 | * @param string $className |
||
| 271 | * @param string $fieldName |
||
| 272 | * @param string $strategy |
||
| 273 | * @return MappingException |
||
| 274 | */ |
||
| 275 | 1 | public static function referenceManySortMustNotBeUsedWithNonSetCollectionStrategy($className, $fieldName, $strategy) |
|
| 279 | |||
| 280 | /** |
||
| 281 | * @param string $className |
||
| 282 | * @param string $fieldName |
||
| 283 | * @param string $type |
||
| 284 | * @param string $strategy |
||
| 285 | * @return MappingException |
||
| 286 | */ |
||
| 287 | public static function invalidStorageStrategy($className, $fieldName, $type, $strategy) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @param string $className |
||
| 294 | * @param string $fieldName |
||
| 295 | * @param string $collectionClass |
||
| 296 | * @return MappingException |
||
| 297 | */ |
||
| 298 | 1 | public static function collectionClassDoesNotImplementCommonInterface($className, $fieldName, $collectionClass) |
|
| 302 | |||
| 303 | /** |
||
| 304 | * @param string $subclassName |
||
| 305 | * @return MappingException |
||
| 306 | */ |
||
| 307 | 2 | public static function shardKeyInSingleCollInheritanceSubclass($subclassName) |
|
| 311 | |||
| 312 | /** |
||
| 313 | * @param string $className |
||
| 314 | * @return MappingException |
||
| 315 | */ |
||
| 316 | 2 | public static function embeddedDocumentCantHaveShardKey($className) |
|
| 320 | |||
| 321 | /** |
||
| 322 | * @param string $className |
||
| 323 | * @param string $fieldName |
||
| 324 | * @return MappingException |
||
| 325 | */ |
||
| 326 | 1 | public static function onlySetStrategyAllowedInShardKey($className, $fieldName) |
|
| 330 | |||
| 331 | /** |
||
| 332 | * @param string $className |
||
| 333 | * @param string $fieldName |
||
| 334 | * @return MappingException |
||
| 335 | */ |
||
| 336 | 3 | public static function noMultiKeyShardKeys($className, $fieldName) |
|
| 340 | |||
| 341 | /** |
||
| 342 | * @param string $className |
||
| 343 | * @param string $fieldName |
||
| 344 | * @return MappingException |
||
| 345 | */ |
||
| 346 | public static function cannotLookupDbRefReference($className, $fieldName) |
||
| 350 | |||
| 351 | /** |
||
| 352 | * @param string $className |
||
| 353 | * @param string $fieldName |
||
| 354 | * @return MappingException |
||
| 355 | */ |
||
| 356 | public static function repositoryMethodLookupNotAllowed($className, $fieldName) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @param string $className |
||
| 363 | * @return MappingException |
||
| 364 | */ |
||
| 365 | 1 | public static function cannotUseShardedCollectionInOutStage($className) |
|
| 369 | |||
| 370 | /** |
||
| 371 | * @param string $className |
||
| 372 | * @return MappingException |
||
| 373 | */ |
||
| 374 | 3 | public static function cannotUseShardedCollectionInLookupStages($className) |
|
| 378 | |||
| 379 | /** |
||
| 380 | * @param string $className |
||
| 381 | * @param string $fieldName |
||
| 382 | * |
||
| 383 | * @return MappingException |
||
| 384 | */ |
||
| 385 | public static function referencePrimersOnlySupportedForInverseReferenceMany($className, $fieldName) |
||
| 389 | |||
| 390 | 1 | public static function connectFromFieldMustReferenceSameDocument($fieldName) |
|
| 394 | |||
| 395 | 3 | public static function repositoryMethodCanNotBeCombinedWithSkipLimitAndSort($className, $fieldName) |
|
| 399 | |||
| 400 | 2 | public static function xmlMappingFileInvalid(string $filename, string $errorDetails): self |
|
| 404 | |||
| 405 | 1 | public static function fieldNotAllowedForGridFS($className, $fieldName) |
|
| 409 | |||
| 410 | public static function discriminatorNotAllowedForGridFS($className) |
||
| 414 | } |
||
| 415 |