Completed
Push — master ( bb3219...cc367c )
by Andreas
15:44
created

MappingException::cannotLookupDbRefReference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Mapping;
6
7
use Doctrine\Common\Collections\Collection;
8
use Doctrine\Common\Persistence\Mapping\MappingException as BaseMappingException;
9
use ReflectionException;
10
use function sprintf;
11
12
/**
13
 * Class for all exceptions related to the Doctrine MongoDB ODM
14
 */
15
class MappingException extends BaseMappingException
16
{
17
    public static function typeExists(string $name) : self
18
    {
19
        return new self(sprintf('Type %s already exists.', $name));
20
    }
21
22
    public static function typeNotFound(string $name) : self
23
    {
24
        return new self(sprintf('Type to be overwritten %s does not exist.', $name));
25
    }
26
27 6
    public static function mappingNotFound(string $className, string $fieldName) : self
28
    {
29 6
        return new self(sprintf("No mapping found for field '%s' in class '%s'.", $fieldName, $className));
30
    }
31
32
    public static function referenceMappingNotFound(string $className, string $fieldName) : self
33
    {
34
        return new self(sprintf("No reference mapping found for field '%s' in class '%s'.", $fieldName, $className));
35
    }
36
37 2
    public static function mappingNotFoundInClassNorDescendants(string $className, string $fieldName) : self
38
    {
39 2
        return new self(sprintf("No mapping found for field '%s' in class '%s' nor its descendants.", $fieldName, $className));
40
    }
41
42 2
    public static function referenceFieldConflict(string $fieldName, string $className, string $className2) : self
43
    {
44 2
        return new self(sprintf("Reference mapping for field '%s' in class '%s' conflicts with one mapped in class '%s'.", $fieldName, $className, $className2));
45
    }
46
47 1
    public static function mappingNotFoundByDbName(string $className, string $dbFieldName) : self
48
    {
49 1
        return new self(sprintf("No mapping found for field by DB name '%s' in class '%s'.", $dbFieldName, $className));
50
    }
51
52
    public static function duplicateFieldMapping(string $document, string $fieldName) : self
53
    {
54
        return new self(sprintf('Property "%s" in "%s" was already declared, but it must be declared only once', $fieldName, $document));
55
    }
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 2
    public static function discriminatorFieldConflict(string $document, string $fieldName) : self
63
    {
64 2
        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
73
    {
74
        return new self(sprintf("Discriminator value '%s' used in the declaration of class '%s' does not exist.", $value, $owningClass));
75
    }
76
77
    public static function missingFieldName(string $className) : self
78
    {
79
        return new self(sprintf("The Document class '%s' field mapping misses the 'fieldName' attribute.", $className));
80
    }
81
82 3
    public static function classIsNotAValidDocument(string $className) : self
83
    {
84 3
        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
88
    {
89
        return new self('An error occurred in ' . $document, 0, $previousException);
90
    }
91
92
    public static function identifierRequired(string $documentName) : self
93
    {
94
        return new self(sprintf("No identifier/primary key specified for Document '%s'. Every Document must have an identifier/primary key.", $documentName));
95
    }
96
97
    public static function missingIdentifierField(string $className, string $fieldName) : self
98
    {
99
        return new self(sprintf('The identifier %s is missing for a query of %s', $fieldName, $className));
100
    }
101
102
    public static function missingIdGeneratorClass(string $className) : self
103
    {
104
        return new self(sprintf('The class-option for the custom ID generator is missing in class %s.', $className));
105
    }
106
107
    public static function classIsNotAValidGenerator(string $className) : self
108
    {
109
        return new self(sprintf('The class %s if not a valid ID generator of type AbstractIdGenerator.', $className));
110
    }
111
112
    public static function missingGeneratorSetter(string $className, string $optionName) : self
113
    {
114
        return new self(sprintf('The class %s is missing a setter for the option %s.', $className, $optionName));
115
    }
116
117 1
    public static function cascadeOnEmbeddedNotAllowed(string $className, string $fieldName) : self
118
    {
119 1
        return new self(sprintf('Cascade on %s::%s is not allowed.', $className, $fieldName));
120
    }
121
122 3
    public static function simpleReferenceRequiresTargetDocument(string $className, string $fieldName) : self
123
    {
124 3
        return new self(sprintf('Target document must be specified for identifier reference: %s::%s', $className, $fieldName));
125
    }
126
127 1
    public static function simpleReferenceMustNotTargetDiscriminatedDocument(string $targetDocument) : self
128
    {
129 1
        return new self(sprintf('Identifier reference must not target document using Single Collection Inheritance, %s targeted.', $targetDocument));
130
    }
131
132 1
    public static function atomicCollectionStrategyNotAllowed(string $strategy, string $className, string $fieldName) : self
133
    {
134 1
        return new self(sprintf('%s collection strategy can be used only in top level document, used in %s::%s', $strategy, $className, $fieldName));
135
    }
136
137 4
    public static function owningAndInverseReferencesRequireTargetDocument(string $className, string $fieldName) : self
138
    {
139 4
        return new self(sprintf('Target document must be specified for owning/inverse sides of reference: %s::%s', $className, $fieldName));
140
    }
141
142 1
    public static function mustNotChangeIdentifierFieldsType(string $className, string $fieldName) : self
143
    {
144 1
        return new self(sprintf('%s::%s was declared an identifier and must stay this way.', $className, $fieldName));
145
    }
146
147 1
    public static function referenceManySortMustNotBeUsedWithNonSetCollectionStrategy(string $className, string $fieldName, string $strategy) : self
148
    {
149 1
        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
    public static function invalidStorageStrategy(string $className, string $fieldName, string $type, string $strategy) : self
153
    {
154
        return new self(sprintf('Invalid strategy %s used in %s::%s with type %s', $strategy, $className, $fieldName, $type));
155
    }
156
157 1
    public static function collectionClassDoesNotImplementCommonInterface(string $className, string $fieldName, string $collectionClass) : self
158
    {
159 1
        return new self(sprintf('%s used as custom collection class for %s::%s has to implement %s interface.', $collectionClass, $className, $fieldName, Collection::class));
160
    }
161
162 2
    public static function shardKeyInSingleCollInheritanceSubclass(string $subclassName) : self
163
    {
164 2
        return new self(sprintf('Shard key overriding in subclass is forbidden for single collection inheritance: %s', $subclassName));
165
    }
166
167 2
    public static function embeddedDocumentCantHaveShardKey(string $className) : self
168
    {
169 2
        return new self(sprintf("Embedded document can't have shard key: %s", $className));
170
    }
171
172 1
    public static function onlySetStrategyAllowedInShardKey(string $className, string $fieldName) : self
173
    {
174 1
        return new self(sprintf('Only fields using the SET strategy can be used in the shard key: %s::%s', $className, $fieldName));
175
    }
176
177 3
    public static function noMultiKeyShardKeys(string $className, string $fieldName) : self
178
    {
179 3
        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
183
    {
184
        return new self(sprintf("Cannot use reference '%s' in class '%s' for lookup or graphLookup: dbRef references are not supported.", $fieldName, $className));
185
    }
186
187
    public static function repositoryMethodLookupNotAllowed(string $className, string $fieldName) : self
188
    {
189
        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 1
    public static function cannotUseShardedCollectionInOutStage(string $className) : self
193
    {
194 1
        return new self(sprintf("Cannot use class '%s' as collection for out stage. Sharded collections are not allowed.", $className));
195
    }
196
197 3
    public static function cannotUseShardedCollectionInLookupStages(string $className) : self
198
    {
199 3
        return new self(sprintf("Cannot use class '%s' as collection for lookup or graphLookup stage. Sharded collections are not allowed.", $className));
200
    }
201
202
    public static function referencePrimersOnlySupportedForInverseReferenceMany(string $className, string $fieldName) : self
203
    {
204
        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 1
    public static function connectFromFieldMustReferenceSameDocument(string $fieldName) : self
208
    {
209 1
        return new self(sprintf("Cannot use field '%s' as connectFromField in a \$graphLookup stage. Reference must target the document itself.", $fieldName));
210
    }
211
212 3
    public static function repositoryMethodCanNotBeCombinedWithSkipLimitAndSort(string $className, string $fieldName) : self
213
    {
214 3
        return new self(sprintf("'repositoryMethod' used on '%s' in class '%s' can not be combined with skip, limit or sort.", $fieldName, $className));
215
    }
216
217 2
    public static function xmlMappingFileInvalid(string $filename, string $errorDetails) : self
218
    {
219 2
        return new self(sprintf("The mapping file %s is invalid: \n%s", $filename, $errorDetails));
220
    }
221
222 1
    public static function fieldNotAllowedForGridFS(string $className, string $fieldName) : self
223
    {
224 1
        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