Test Failed
Pull Request — develop (#6743)
by Grégoire
61:16
created

ORMException::invalidFindByInverseAssociation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A ORMException::cantUseInOperatorOnCompositeKeys() 0 4 1
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
     * @param string $nativeQueryName
20
     *
21
     * @return ORMException
22
     */
23
    public static function namedNativeQueryNotFound($nativeQueryName)
24
    {
25
        return new self('Could not find a named native query by the name "' . $nativeQueryName . '"');
26
    }
27
28
    /**
29
     * @param string $field
30
     *
31
     * @return ORMException
32
     */
33
    public static function unrecognizedField($field)
34
    {
35
        return new self("Unrecognized field: $field");
36
    }
37
38
    /**
39
     *
40
     * @param string $class
41
     * @param string $association
42
     * @param string $given
43
     * @param string $expected
44
     *
45
     * @return \Doctrine\ORM\ORMInvalidArgumentException
46
     */
47 2
    public static function unexpectedAssociationValue($class, $association, $given, $expected)
48
    {
49 2
        return new self(sprintf('Found entity of type %s on association %s#%s, but expecting %s', $given, $class, $association, $expected));
50
    }
51
52
    /**
53
     * @param string $className
54
     * @param string $field
55
     *
56
     * @return ORMException
57
     */
58
    public static function invalidOrientation($className, $field)
59
    {
60
        return new self("Invalid order by orientation specified for " . $className . "#" . $field);
61
    }
62
63
    /**
64
     * @return ORMException
65
     */
66
    public static function entityManagerClosed()
67
    {
68
        return new self("The EntityManager is closed.");
69
    }
70
71
    /**
72
     * @param string $mode
73
     *
74
     * @return ORMException
75
     */
76
    public static function invalidHydrationMode($mode)
77
    {
78
        return new self("'$mode' is an invalid hydration mode.");
79
    }
80
81
    /**
82
     * @return ORMException
83
     */
84
    public static function mismatchedEventManager()
85 1
    {
86
        return new self("Cannot use different EventManager instances for EntityManager and Connection.");
87 1
    }
88 1
89 1
    /**
90 1
     * @return ORMException
91
     */
92
    public static function invalidResultCacheDriver()
93
    {
94
        return new self("Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.");
95
    }
96
97
    /**
98
     * @return ORMException
99 3
     */
100
    public static function notSupported()
101 3
    {
102
        return new self("This behaviour is (currently) not supported by Doctrine 2");
103
    }
104
105
    /**
106
     * @return ORMException
107
     */
108
    public static function queryCacheNotConfigured()
109
    {
110
        return new self('Query Cache is not configured.');
111
    }
112
113
    /**
114
     * @return ORMException
115
     */
116
    public static function metadataCacheNotConfigured()
117
    {
118
        return new self('Class Metadata Cache is not configured.');
119
    }
120
121
    /**
122
     * @param \Doctrine\Common\Cache\Cache $cache
123
     *
124 1
     * @return ORMException
125
     */
126 1
    public static function queryCacheUsesNonPersistentCache(CacheDriver $cache)
127
    {
128
        return new self('Query Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
129
    }
130
131
    /**
132
     * @param \Doctrine\Common\Cache\Cache $cache
133
     *
134
     * @return ORMException
135
     */
136
    public static function metadataCacheUsesNonPersistentCache(CacheDriver $cache)
137
    {
138
        return new self('Metadata Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
139
    }
140
141
    /**
142 5
     * @return ORMException
143
     */
144 5
    public static function proxyClassesAlwaysRegenerating()
145
    {
146
        return new self('Proxy Classes are always regenerating.');
147
    }
148
149
    /**
150
     * @param string $entityNamespaceAlias
151
     *
152
     * @return ORMException
153
     */
154
    public static function unknownEntityNamespace($entityNamespaceAlias)
155
    {
156
        return new self(
157
            "Unknown Entity namespace alias '$entityNamespaceAlias'."
158
        );
159
    }
160
161
    /**
162
     * @param string $className
163
     *
164
     * @return ORMException
165
     */
166
    public static function invalidEntityRepository($className)
167
    {
168
        return new self("Invalid repository class '".$className."'. It must be a Doctrine\Common\Persistence\ObjectRepository.");
169
    }
170 1
171
    /**
172 1
     * @param string $className
173
     * @param string $fieldName
174
     *
175
     * @return ORMException
176
     */
177
    public static function missingIdentifierField($className, $fieldName)
178
    {
179
        return new self("The identifier $fieldName is missing for a query of " . $className);
180
    }
181
182 1
    /**
183
     * @param string $className
184 1
     * @param string[] $fieldNames
185 1
     *
186 1
     * @return ORMException
187
     */
188
    public static function unrecognizedIdentifierFields($className, $fieldNames)
189
    {
190
        return new self(
191
            "Unrecognized identifier fields: '" . implode("', '", $fieldNames) . "' " .
192
            "are not present on class '" . $className . "'."
193
        );
194
    }
195
196 2
    /**
197
     * @return ORMException
198 2
     */
199 2
    public static function cantUseInOperatorOnCompositeKeys()
200 2
    {
201
        return new self("Can't use IN operator on entities that have composite keys.");
202
    }
203
}
204