Completed
Pull Request — develop (#6743)
by Grégoire
61:28
created

ORMException::entityMissingAssignedIdForField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 2
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
 * @author Roman Borschel <[email protected]>
14
 * @since 2.0
15
 */
16
class ORMException extends Exception
17
{
18
    /**
19
     * @return ORMException
20
     */
21
    public static function missingMappingDriverImpl()
22
    {
23
        return new self("It's a requirement to specify a Metadata Driver and pass it ".
24
            "to Doctrine\\ORM\\Configuration::setMetadataDriverImpl().");
25
    }
26
27
    /**
28
     * @param string $queryName
29
     *
30
     * @return ORMException
31
     */
32
    public static function namedQueryNotFound($queryName)
33
    {
34
        return new self('Could not find a named query by the name "' . $queryName . '"');
35
    }
36
37
    /**
38
     * @param string $nativeQueryName
39
     *
40
     * @return ORMException
41
     */
42
    public static function namedNativeQueryNotFound($nativeQueryName)
43
    {
44
        return new self('Could not find a named native query by the name "' . $nativeQueryName . '"');
45
    }
46
47 2
    /**
48
     * @param string $field
49 2
     *
50
     * @return ORMException
51
     */
52
    public static function unrecognizedField($field)
53
    {
54
        return new self("Unrecognized field: $field");
55
    }
56
57
    /**
58
     *
59
     * @param string $class
60
     * @param string $association
61
     * @param string $given
62
     * @param string $expected
63
     *
64
     * @return \Doctrine\ORM\ORMInvalidArgumentException
65
     */
66
    public static function unexpectedAssociationValue($class, $association, $given, $expected)
67
    {
68
        return new self(sprintf('Found entity of type %s on association %s#%s, but expecting %s', $given, $class, $association, $expected));
69
    }
70
71
    /**
72
     * @param string $className
73
     * @param string $field
74
     *
75
     * @return ORMException
76
     */
77
    public static function invalidOrientation($className, $field)
78
    {
79
        return new self("Invalid order by orientation specified for " . $className . "#" . $field);
80
    }
81
82
    /**
83
     * @return ORMException
84
     */
85 1
    public static function entityManagerClosed()
86
    {
87 1
        return new self("The EntityManager is closed.");
88 1
    }
89 1
90 1
    /**
91
     * @param string $mode
92
     *
93
     * @return ORMException
94
     */
95
    public static function invalidHydrationMode($mode)
96
    {
97
        return new self("'$mode' is an invalid hydration mode.");
98
    }
99 3
100
    /**
101 3
     * @return ORMException
102
     */
103
    public static function mismatchedEventManager()
104
    {
105
        return new self("Cannot use different EventManager instances for EntityManager and Connection.");
106
    }
107
108
    /**
109
     * @param string $methodName
110
     *
111
     * @return ORMException
112
     */
113
    public static function findByRequiresParameter($methodName)
114
    {
115
        return new self("You need to pass a parameter to '".$methodName."'");
116
    }
117
118
    /**
119
     * @param string $entityName
120
     * @param string $fieldName
121
     * @param string $method
122
     *
123
     * @return ORMException
124 1
     */
125
    public static function invalidMagicCall($entityName, $fieldName, $method)
126 1
    {
127
        return new self(
128
            "Entity '".$entityName."' has no field '".$fieldName."'. ".
129
            "You can therefore not call '".$method."' on the entities' repository"
130
        );
131
    }
132
133
    /**
134
     * @param string $entityName
135
     * @param string $associationFieldName
136
     *
137
     * @return ORMException
138
     */
139
    public static function invalidFindByInverseAssociation($entityName, $associationFieldName)
140
    {
141
        return new self(
142 5
            "You cannot search for the association field '".$entityName."#".$associationFieldName."', ".
143
            "because it is the inverse side of an association. Find methods only work on owning side associations."
144 5
        );
145
    }
146
147
    /**
148
     * @return ORMException
149
     */
150
    public static function invalidResultCacheDriver()
151
    {
152
        return new self("Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.");
153
    }
154
155
    /**
156
     * @return ORMException
157
     */
158
    public static function notSupported()
159
    {
160
        return new self("This behaviour is (currently) not supported by Doctrine 2");
161
    }
162
163
    /**
164
     * @return ORMException
165
     */
166
    public static function queryCacheNotConfigured()
167
    {
168
        return new self('Query Cache is not configured.');
169
    }
170 1
171
    /**
172 1
     * @return ORMException
173
     */
174
    public static function metadataCacheNotConfigured()
175
    {
176
        return new self('Class Metadata Cache is not configured.');
177
    }
178
179
    /**
180
     * @param \Doctrine\Common\Cache\Cache $cache
181
     *
182 1
     * @return ORMException
183
     */
184 1
    public static function queryCacheUsesNonPersistentCache(CacheDriver $cache)
185 1
    {
186 1
        return new self('Query Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
187
    }
188
189
    /**
190
     * @param \Doctrine\Common\Cache\Cache $cache
191
     *
192
     * @return ORMException
193
     */
194
    public static function metadataCacheUsesNonPersistentCache(CacheDriver $cache)
195
    {
196 2
        return new self('Metadata Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
197
    }
198 2
199 2
    /**
200 2
     * @return ORMException
201
     */
202
    public static function proxyClassesAlwaysRegenerating()
203
    {
204
        return new self('Proxy Classes are always regenerating.');
205
    }
206
207
    /**
208
     * @param string $entityNamespaceAlias
209
     *
210
     * @return ORMException
211
     */
212
    public static function unknownEntityNamespace($entityNamespaceAlias)
213
    {
214
        return new self(
215
            "Unknown Entity namespace alias '$entityNamespaceAlias'."
216
        );
217
    }
218
219
    /**
220
     * @param string $className
221
     *
222
     * @return ORMException
223 1
     */
224
    public static function invalidEntityRepository($className)
225 1
    {
226
        return new self("Invalid repository class '".$className."'. It must be a Doctrine\Common\Persistence\ObjectRepository.");
227
    }
228
229
    /**
230
     * @param string $className
231 1
     * @param string $fieldName
232
     *
233 1
     * @return ORMException
234
     */
235
    public static function missingIdentifierField($className, $fieldName)
236
    {
237
        return new self("The identifier $fieldName is missing for a query of " . $className);
238
    }
239
240
    /**
241 1
     * @param string $className
242
     * @param string[] $fieldNames
243 1
     *
244
     * @return ORMException
245
     */
246
    public static function unrecognizedIdentifierFields($className, $fieldNames)
247
    {
248
        return new self(
249
            "Unrecognized identifier fields: '" . implode("', '", $fieldNames) . "' " .
250
            "are not present on class '" . $className . "'."
251 1
        );
252
    }
253 1
254
    /**
255
     * @return ORMException
256
     */
257
    public static function cantUseInOperatorOnCompositeKeys()
258
    {
259 3
        return new self("Can't use IN operator on entities that have composite keys.");
260
    }
261
}
262