Failed Conditions
Push — master ( 8be1e3...e3936d )
by Marco
14s
created

ORMException::invalidHydrationMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM;
6
7
use Doctrine\Common\Cache\Cache as CacheDriver;
8
use Exception;
9
10
/**
11
 * Base exception class for all ORM exceptions.
12
 */
13
class ORMException extends Exception
14
{
15
    /**
16
     * @return ORMException
17
     */
18
    public static function missingMappingDriverImpl()
19
    {
20
        return new self("It's a requirement to specify a Metadata Driver and pass it " .
21
            'to Doctrine\\ORM\\Configuration::setMetadataDriverImpl().');
22
    }
23
24
    /**
25
     * @param string $queryName
26
     *
27
     * @return ORMException
28
     */
29 1
    public static function namedQueryNotFound($queryName)
30
    {
31 1
        return new self('Could not find a named query by the name "' . $queryName . '"');
32
    }
33
34
    /**
35
     * @param string $nativeQueryName
36
     *
37
     * @return ORMException
38
     */
39 1
    public static function namedNativeQueryNotFound($nativeQueryName)
40
    {
41 1
        return new self('Could not find a named native query by the name "' . $nativeQueryName . '"');
42
    }
43
44
    /**
45
     * @param object $entity
46
     * @param object $relatedEntity
47
     *
48
     * @return ORMException
49
     */
50
    public static function entityMissingForeignAssignedId($entity, $relatedEntity)
51
    {
52
        return new self(
53
            'Entity of type ' . get_class($entity) . ' has identity through a foreign entity ' . get_class($relatedEntity) . ', ' .
54
            'however this entity has no identity itself. You have to call EntityManager#persist() on the related entity ' .
55
            "and make sure that an identifier was generated before trying to persist '" . get_class($entity) . "'. In case " .
56
            'of Post Insert ID Generation (such as MySQL Auto-Increment) this means you have to call ' .
57
            'EntityManager#flush() between both persist operations.'
58
        );
59
    }
60
61
    /**
62
     * @param object $entity
63
     * @param string $field
64
     *
65
     * @return ORMException
66
     */
67
    public static function entityMissingAssignedIdForField($entity, $field)
68
    {
69
        return new self('Entity of type ' . get_class($entity) . " is missing an assigned ID for field  '" . $field . "'. " .
70
            'The identifier generation strategy for this entity requires the ID field to be populated before ' .
71
            'EntityManager#persist() is called. If you want automatically generated identifiers instead ' .
72
            'you need to adjust the metadata mapping accordingly.');
73
    }
74
75
    /**
76
     * @param string $field
77
     *
78
     * @return ORMException
79
     */
80 3
    public static function unrecognizedField($field)
81
    {
82 3
        return new self('Unrecognized field: ' . $field);
83
    }
84
85
    /**
86
     * @param string $class
87
     * @param string $association
88
     * @param string $given
89
     * @param string $expected
90
     *
91
     * @return \Doctrine\ORM\ORMInvalidArgumentException
92
     */
93
    public static function unexpectedAssociationValue($class, $association, $given, $expected)
94
    {
95
        return new self(sprintf('Found entity of type %s on association %s#%s, but expecting %s', $given, $class, $association, $expected));
0 ignored issues
show
Bug Best Practice introduced by
The expression return new self(sprintf(...ssociation, $expected)) returns the type Doctrine\ORM\ORMException which is incompatible with the documented return type Doctrine\ORM\ORMInvalidArgumentException.
Loading history...
96
    }
97
98
    /**
99
     * @param string $className
100
     * @param string $field
101
     *
102
     * @return ORMException
103
     */
104 1
    public static function invalidOrientation($className, $field)
105
    {
106 1
        return new self('Invalid order by orientation specified for ' . $className . '#' . $field);
107
    }
108
109
    /**
110
     * @param string $mode
111
     *
112
     * @return ORMException
113
     */
114
    public static function invalidFlushMode($mode)
115
    {
116
        return new self(sprintf("'%s' is an invalid flush mode.", $mode));
117
    }
118
119
    /**
120
     * @return ORMException
121
     */
122 4
    public static function entityManagerClosed()
123
    {
124 4
        return new self('The EntityManager is closed.');
125
    }
126
127
    /**
128
     * @param string $mode
129
     *
130
     * @return ORMException
131
     */
132
    public static function invalidHydrationMode($mode)
133
    {
134
        return new self(sprintf("'%s' is an invalid hydration mode.", $mode));
135
    }
136
137
    /**
138
     * @return ORMException
139
     */
140
    public static function mismatchedEventManager()
141
    {
142
        return new self('Cannot use different EventManager instances for EntityManager and Connection.');
143
    }
144
145
    /**
146
     * @param string $methodName
147
     *
148
     * @return ORMException
149
     */
150 1
    public static function findByRequiresParameter($methodName)
151
    {
152 1
        return new self("You need to pass a parameter to '" . $methodName . "'");
153
    }
154
155
    /**
156
     * @param string $entityName
157
     * @param string $fieldName
158
     * @param string $method
159
     *
160
     * @return ORMException
161
     */
162
    public static function invalidFindByCall($entityName, $fieldName, $method)
163
    {
164
        return new self(
165
            "Entity '" . $entityName . "' has no field '" . $fieldName . "'. " .
166
            "You can therefore not call '" . $method . "' on the entities' repository"
167
        );
168
    }
169
170
    /**
171
     * @param string $entityName
172
     * @param string $fieldName
173
     * @param string $method
174
     *
175
     * @return ORMException
176
     */
177 1
    public static function invalidMagicCall($entityName, $fieldName, $method)
178
    {
179 1
        return new self(
180 1
            "Entity '" . $entityName . "' has no field '" . $fieldName . "'. " .
181 1
            "You can therefore not call '" . $method . "' on the entities' repository"
182
        );
183
    }
184
185
    /**
186
     * @param string $entityName
187
     * @param string $associationFieldName
188
     *
189
     * @return ORMException
190
     */
191 2
    public static function invalidFindByInverseAssociation($entityName, $associationFieldName)
192
    {
193 2
        return new self(
194 2
            "You cannot search for the association field '" . $entityName . '#' . $associationFieldName . "', " .
195 2
            'because it is the inverse side of an association. Find methods only work on owning side associations.'
196
        );
197
    }
198
199
    /**
200
     * @return ORMException
201
     */
202
    public static function invalidResultCacheDriver()
203
    {
204
        return new self('Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.');
205
    }
206
207
    /**
208
     * @return ORMException
209
     */
210
    public static function notSupported()
211
    {
212
        return new self('This behaviour is (currently) not supported by Doctrine 2');
213
    }
214
215
    /**
216
     * @return ORMException
217
     */
218 1
    public static function queryCacheNotConfigured()
219
    {
220 1
        return new self('Query Cache is not configured.');
221
    }
222
223
    /**
224
     * @return ORMException
225
     */
226 1
    public static function metadataCacheNotConfigured()
227
    {
228 1
        return new self('Class Metadata Cache is not configured.');
229
    }
230
231
    /**
232
     * @return ORMException
233
     */
234 1
    public static function queryCacheUsesNonPersistentCache(CacheDriver $cache)
235
    {
236 1
        return new self('Query Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
237
    }
238
239
    /**
240
     * @return ORMException
241
     */
242 1
    public static function metadataCacheUsesNonPersistentCache(CacheDriver $cache)
243
    {
244 1
        return new self('Metadata Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
245
    }
246
247
    /**
248
     * @return ORMException
249
     */
250 1
    public static function proxyClassesAlwaysRegenerating()
251
    {
252 1
        return new self('Proxy Classes are always regenerating.');
253
    }
254
255
    /**
256
     * @param string $entityNamespaceAlias
257
     *
258
     * @return ORMException
259
     */
260 1
    public static function unknownEntityNamespace($entityNamespaceAlias)
261
    {
262 1
        return new self(sprintf("Unknown Entity namespace alias '%s'.", $entityNamespaceAlias));
263
    }
264
265
    /**
266
     * @param string $className
267
     *
268
     * @return ORMException
269
     */
270 1
    public static function invalidEntityRepository($className)
271
    {
272 1
        return new self("Invalid repository class '" . $className . "'. It must be a Doctrine\Common\Persistence\ObjectRepository.");
273
    }
274
275
    /**
276
     * @param string $className
277
     * @param string $fieldName
278
     *
279
     * @return ORMException
280
     */
281 1
    public static function missingIdentifierField($className, $fieldName)
282
    {
283 1
        return new self(sprintf('The identifier %s is missing for a query of %s', $fieldName, $className));
284
    }
285
286
    /**
287
     * @param string   $className
288
     * @param string[] $fieldNames
289
     *
290
     * @return ORMException
291
     */
292 2
    public static function unrecognizedIdentifierFields($className, $fieldNames)
293
    {
294 2
        return new self(
295 2
            "Unrecognized identifier fields: '" . implode("', '", $fieldNames) . "' " .
296 2
            "are not present on class '" . $className . "'."
297
        );
298
    }
299
300
    /**
301
     * @return ORMException
302
     */
303 1
    public static function cantUseInOperatorOnCompositeKeys()
304
    {
305 1
        return new self("Can't use IN operator on entities that have composite keys.");
306
    }
307
}
308