Failed Conditions
Pull Request — master (#8010)
by Oleg
09:21
created

QueryException   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 254
Duplicated Lines 0 %

Test Coverage

Coverage 55.38%

Importance

Changes 0
Metric Value
eloc 48
c 0
b 0
f 0
dl 0
loc 254
ccs 36
cts 65
cp 0.5538
rs 10
wmc 24

24 Methods

Rating   Name   Duplication   Size   Complexity  
A invalidLiteral() 0 3 1
A instanceOfUnrelatedClass() 0 4 1
A invalidPathExpression() 0 4 1
A parameterTypeMismatch() 0 3 1
A invalidParameterType() 0 3 1
A tooManyParameters() 0 3 1
A unknownParameter() 0 3 1
A overwritingJoinConditionsNotYetSupported() 0 6 1
A iterateWithFetchJoinCollectionNotAllowed() 0 5 1
A invalidParameterPosition() 0 3 1
A associationPathInverseSideNotSupported() 0 5 1
A iterateWithFetchJoinNotAllowed() 0 7 1
A associationPathCompositeKeyNotSupported() 0 6 1
A partialObjectsAreDangerous() 0 6 1
A syntaxError() 0 3 1
A invalidQueryComponent() 0 5 1
A dqlError() 0 3 1
A invalidLockMode() 0 3 1
A invalidParameterFormat() 0 3 1
A tooFewParameters() 0 3 1
A semanticalError() 0 3 1
A specifiedRootAliasMustBeSetBeforeInvokingIndexBy() 0 4 1
A missingSelectExpression() 0 4 1
A noAliasesBeforeInvokingCriteria() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Query;
6
7
use Doctrine\ORM\Exception\ORMException;
8
use Doctrine\ORM\Mapping\AssociationMetadata;
9
use Doctrine\ORM\Query\AST\PathExpression;
10
use Exception;
11
use LogicException;
12
use Throwable;
13
use function sprintf;
14
15
/**
16
 * Description of QueryException.
17
 */
18
class QueryException extends LogicException implements ORMException
19
{
20
    /**
21
     * @param string $dql
22
     *
23
     * @return QueryException
24
     */
25 43
    public static function dqlError($dql, ?Throwable $previous = null)
26
    {
27 43
        return new self($dql, 0, $previous);
28
    }
29
30
    /**
31
     * @param string         $message
32
     * @param Exception|null $previous
33
     *
34
     * @return QueryException
35
     */
36 18
    public static function syntaxError($message, $previous = null)
37
    {
38 18
        return new self('[Syntax Error] ' . $message, 0, $previous);
39
    }
40
41
    /**
42
     * @param string         $message
43
     * @param Exception|null $previous
44
     *
45
     * @return QueryException
46
     */
47 26
    public static function semanticalError($message, $previous = null)
48
    {
49 26
        return new self('[Semantical Error] ' . $message, 0, $previous);
50
    }
51
52
    /**
53
     * @return QueryException
54
     */
55
    public static function invalidLockMode()
56
    {
57
        return new self('Invalid lock mode hint provided.');
58
    }
59
60
    /**
61
     * @param string $expected
62
     * @param string $received
63
     *
64
     * @return QueryException
65
     */
66
    public static function invalidParameterType($expected, $received)
67
    {
68
        return new self('Invalid parameter type, ' . $received . ' given, but ' . $expected . ' expected.');
69
    }
70
71
    /**
72
     * @param string $pos
73
     *
74
     * @return QueryException
75
     */
76
    public static function invalidParameterPosition($pos)
77
    {
78
        return new self('Invalid parameter position: ' . $pos);
79
    }
80
81
    /**
82
     * @param int $expected
83
     * @param int $received
84
     *
85
     * @return QueryException
86
     */
87 2
    public static function tooManyParameters($expected, $received)
88
    {
89 2
        return new self('Too many parameters: the query defines ' . $expected . ' parameters and you bound ' . $received);
90
    }
91
92
    /**
93
     * @param int $expected
94
     * @param int $received
95
     *
96
     * @return QueryException
97
     */
98 1
    public static function tooFewParameters($expected, $received)
99
    {
100 1
        return new self('Too few parameters: the query defines ' . $expected . ' parameters but you only bound ' . $received);
101
    }
102
103
    /**
104
     * @param string $value
105
     *
106
     * @return QueryException
107
     */
108 2
    public static function invalidParameterFormat($value)
109
    {
110 2
        return new self('Invalid parameter format, ' . $value . ' given, but :<name> or ?<num> expected.');
111
    }
112
113
    /**
114
     * @param string $key
115
     *
116
     * @return QueryException
117
     */
118 1
    public static function unknownParameter($key)
119
    {
120 1
        return new self('Invalid parameter: token ' . $key . ' is not defined in the query.');
121
    }
122
123
    /**
124
     * @return QueryException
125
     */
126
    public static function parameterTypeMismatch()
127
    {
128
        return new self('DQL Query parameter and type numbers mismatch, but have to be exactly equal.');
129
    }
130
131
    /**
132
     * @param object $pathExpr
133
     *
134
     * @return QueryException
135
     */
136
    public static function invalidPathExpression($pathExpr)
137
    {
138
        return new self(
139
            "Invalid PathExpression '" . $pathExpr->identificationVariable . '.' . $pathExpr->field . "'."
140
        );
141
    }
142
143
    /**
144
     * @param string $literal
145
     *
146
     * @return QueryException
147
     */
148
    public static function invalidLiteral($literal)
149
    {
150
        return new self("Invalid literal '" . $literal . "'");
151
    }
152
153
    /**
154
     * @param mixed[] $assoc
155
     *
156
     * @return QueryException
157
     */
158
    public static function iterateWithFetchJoinCollectionNotAllowed($assoc)
159
    {
160
        return new self(
161
            'Invalid query operation: Not allowed to iterate over fetch join collections ' .
162
            'in class ' . $assoc['sourceEntity'] . ' association ' . $assoc['fieldName']
163
        );
164
    }
165
166
    /**
167
     * @return QueryException
168
     */
169
    public static function partialObjectsAreDangerous()
170
    {
171
        return new self(
172
            'Loading partial objects is dangerous. Fetch full objects or consider ' .
173
            'using a different fetch mode. If you really want partial objects, ' .
174
            'set the doctrine.forcePartialLoad query hint to TRUE.'
175
        );
176
    }
177
178
    /**
179
     * @param mixed[] $assoc
180
     *
181
     * @return QueryException
182
     */
183
    public static function overwritingJoinConditionsNotYetSupported($assoc)
184
    {
185
        return new self(
186
            'Unsupported query operation: It is not yet possible to overwrite the join ' .
187
            'conditions in class ' . $assoc['sourceEntityName'] . ' association ' . $assoc['fieldName'] . '. ' .
188
            'Use WITH to append additional join conditions to the association.'
189
        );
190
    }
191
192
    /**
193
     * @return QueryException
194
     */
195 2
    public static function associationPathInverseSideNotSupported(PathExpression $pathExpr)
196
    {
197 2
        return new self(
198
            'A single-valued association path expression to an inverse side is not supported in DQL queries. ' .
199 2
            'Instead of "' . $pathExpr->identificationVariable . '.' . $pathExpr->field . '" use an explicit join.'
200
        );
201
    }
202
203
    /**
204
     * @return QueryException
205
     */
206 2
    public static function iterateWithFetchJoinNotAllowed(AssociationMetadata $association)
207
    {
208 2
        return new self(
209 2
            sprintf(
210 2
                'Iterate with fetch join in class %s using association %s not allowed.',
211 2
                $association->getSourceEntity(),
212 2
                $association->getName()
213
            )
214
        );
215
    }
216
217
    /**
218
     * @return QueryException
219
     */
220 1
    public static function associationPathCompositeKeyNotSupported()
221
    {
222 1
        return new self(
223
            'A single-valued association path expression to an entity with a composite primary ' .
224
            'key is not supported. Explicitly name the components of the composite primary key ' .
225 1
            'in the query.'
226
        );
227
    }
228
229
    /**
230
     * @param string $className
231
     * @param string $rootClass
232
     *
233
     * @return QueryException
234
     */
235 1
    public static function instanceOfUnrelatedClass($className, $rootClass)
236
    {
237 1
        return new self("Cannot check if a child of '" . $rootClass . "' is instanceof '" . $className . "', " .
238 1
            'inheritance hierarchy does not exists between these two classes.');
239
    }
240
241
    /**
242
     * @param string $dqlAlias
243
     *
244
     * @return QueryException
245
     */
246 1
    public static function invalidQueryComponent($dqlAlias)
247
    {
248 1
        return new self(
249 1
            "Invalid query component given for DQL alias '" . $dqlAlias . "', " .
250 1
            "requires 'metadata', 'parent', 'relation', 'map', 'nestingLevel' and 'token' keys."
251
        );
252
    }
253
254 2
    public static function missingSelectExpression() : QueryException
255
    {
256 2
        return new self(
257 2
            'SELECT expression is required for building DQL'
258
        );
259
    }
260
261
    public static function noAliasesBeforeInvokingCriteria() : QueryException
262
    {
263
        return new self(
264
            'No aliases are set before invoking addCriteria().'
265
        );
266
    }
267
268
    public static function specifiedRootAliasMustBeSetBeforeInvokingIndexBy($dqlAlias) : QueryException
269
    {
270
        return new self(
271
            sprintf('Specified root alias %s must be set before invoking indexBy().', $dqlAlias)
272
        );
273
    }
274
}
275