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 | public static function typeExists(string $name) : self |
||
21 | |||
22 | public static function typeNotFound(string $name) : self |
||
26 | |||
27 | 6 | public static function mappingNotFound(string $className, string $fieldName) : self |
|
31 | |||
32 | public static function referenceMappingNotFound(string $className, string $fieldName) : self |
||
36 | |||
37 | 2 | public static function mappingNotFoundInClassNorDescendants(string $className, string $fieldName) : self |
|
41 | |||
42 | 2 | public static function referenceFieldConflict(string $fieldName, string $className, string $className2) : self |
|
46 | |||
47 | 1 | public static function mappingNotFoundByDbName(string $className, string $dbFieldName) : self |
|
51 | |||
52 | public static function duplicateFieldMapping(string $document, string $fieldName) : self |
||
56 | |||
57 | 2 | public static function duplicateDatabaseFieldName(string $document, string $offendingFieldName, string $databaseName, string $originalFieldName) : self |
|
58 | { |
||
59 | 2 | return new self(sprintf('Field "%s" in class "%s" is mapped to field "%s" in the database, but that name is already in use by field "%s".', $offendingFieldName, $document, $databaseName, $originalFieldName)); |
|
60 | } |
||
61 | |||
62 | public static function discriminatorFieldConflict(string $document, string $fieldName) : self |
||
63 | { |
||
64 | return new self(sprintf('Discriminator field "%s" in "%s" conflicts with a mapped field\'s "name" attribute.', $fieldName, $document)); |
||
65 | } |
||
66 | |||
67 | public static function invalidClassInDiscriminatorMap(string $className, string $owningClass) : self |
||
68 | { |
||
69 | return new self(sprintf("Document class '%s' used in the discriminator map of class '%s' does not exist.", $className, $owningClass)); |
||
70 | } |
||
71 | |||
72 | public static function invalidDiscriminatorValue(string $value, string $owningClass) : self |
||
76 | |||
77 | 3 | public static function missingFieldName(string $className) : self |
|
78 | { |
||
79 | 3 | return new self(sprintf("The Document class '%s' field mapping misses the 'fieldName' attribute.", $className)); |
|
80 | } |
||
81 | |||
82 | public static function classIsNotAValidDocument(string $className) : self |
||
83 | { |
||
84 | return new self(sprintf('Class %s is not a valid document or mapped super class.', $className)); |
||
85 | } |
||
86 | |||
87 | public static function reflectionFailure(string $document, ReflectionException $previousException) : self |
||
91 | |||
92 | public static function identifierRequired(string $documentName) : self |
||
96 | |||
97 | public static function missingIdentifierField(string $className, string $fieldName) : self |
||
101 | |||
102 | public static function missingIdGeneratorClass(string $className) : self |
||
106 | |||
107 | public static function classIsNotAValidGenerator(string $className) : self |
||
111 | |||
112 | 1 | public static function missingGeneratorSetter(string $className, string $optionName) : self |
|
113 | { |
||
114 | 1 | return new self(sprintf('The class %s is missing a setter for the option %s.', $className, $optionName)); |
|
115 | } |
||
116 | |||
117 | 3 | public static function cascadeOnEmbeddedNotAllowed(string $className, string $fieldName) : self |
|
121 | |||
122 | 1 | public static function simpleReferenceRequiresTargetDocument(string $className, string $fieldName) : self |
|
126 | |||
127 | 1 | public static function simpleReferenceMustNotTargetDiscriminatedDocument(string $targetDocument) : self |
|
131 | |||
132 | 4 | public static function atomicCollectionStrategyNotAllowed(string $strategy, string $className, string $fieldName) : self |
|
136 | |||
137 | 1 | public static function owningAndInverseReferencesRequireTargetDocument(string $className, string $fieldName) : self |
|
141 | |||
142 | 1 | public static function mustNotChangeIdentifierFieldsType(string $className, string $fieldName) : self |
|
146 | |||
147 | public static function referenceManySortMustNotBeUsedWithNonSetCollectionStrategy(string $className, string $fieldName, string $strategy) : self |
||
148 | { |
||
149 | return new self(sprintf("ReferenceMany's sort can not be used with addToSet and pushAll strategies, %s used in %s::%s", $strategy, $className, $fieldName)); |
||
150 | } |
||
151 | |||
152 | 1 | public static function invalidStorageStrategy(string $className, string $fieldName, string $type, string $strategy) : self |
|
153 | { |
||
154 | 1 | return new self(sprintf('Invalid strategy %s used in %s::%s with type %s', $strategy, $className, $fieldName, $type)); |
|
155 | } |
||
156 | |||
157 | 2 | public static function collectionClassDoesNotImplementCommonInterface(string $className, string $fieldName, string $collectionClass) : self |
|
161 | |||
162 | 2 | public static function shardKeyInSingleCollInheritanceSubclass(string $subclassName) : self |
|
166 | |||
167 | 1 | public static function embeddedDocumentCantHaveShardKey(string $className) : self |
|
171 | |||
172 | 3 | public static function onlySetStrategyAllowedInShardKey(string $className, string $fieldName) : self |
|
176 | |||
177 | public static function noMultiKeyShardKeys(string $className, string $fieldName) : self |
||
178 | { |
||
179 | return new self(sprintf('No multikey indexes are allowed in the shard key: %s::%s', $className, $fieldName)); |
||
180 | } |
||
181 | |||
182 | public static function cannotLookupDbRefReference(string $className, string $fieldName) : self |
||
186 | |||
187 | 1 | public static function repositoryMethodLookupNotAllowed(string $className, string $fieldName) : self |
|
188 | { |
||
189 | 1 | return new self(sprintf("Cannot use reference '%s' in class '%s' for lookup or graphLookup. repositoryMethod is not supported in \$lookup and \$graphLookup stages.", $fieldName, $className)); |
|
190 | } |
||
191 | |||
192 | 3 | public static function cannotUseShardedCollectionInOutStage(string $className) : self |
|
196 | |||
197 | public static function cannotUseShardedCollectionInLookupStages(string $className) : self |
||
198 | { |
||
199 | return new self(sprintf("Cannot use class '%s' as collection for lookup or graphLookup stage. Sharded collections are not allowed.", $className)); |
||
200 | } |
||
201 | |||
202 | 1 | public static function referencePrimersOnlySupportedForInverseReferenceMany(string $className, string $fieldName) : self |
|
203 | { |
||
204 | 1 | return new self(sprintf("Cannot use reference priming on '%s' in class '%s'. Reference priming is only supported for inverse references", $fieldName, $className)); |
|
205 | } |
||
206 | |||
207 | 3 | public static function connectFromFieldMustReferenceSameDocument(string $fieldName) : self |
|
211 | |||
212 | 2 | public static function repositoryMethodCanNotBeCombinedWithSkipLimitAndSort(string $className, string $fieldName) : self |
|
216 | |||
217 | 1 | public static function xmlMappingFileInvalid(string $filename, string $errorDetails) : self |
|
221 | |||
222 | public static function fieldNotAllowedForGridFS(string $className, string $fieldName) : self |
||
223 | { |
||
224 | return new self(sprintf("Field '%s' in class '%s' is not a valid field for GridFS documents. You should move it to an embedded metadata document.", $fieldName, $className)); |
||
225 | } |
||
226 | |||
227 | public static function discriminatorNotAllowedForGridFS(string $className) : self |
||
228 | { |
||
229 | return new self(sprintf("Class '%s' cannot be discriminated because it is marked as a GridFS file", $className)); |
||
230 | } |
||
231 | } |
||
232 |