Failed Conditions
Push — master ( ddb3cd...4476ec )
by Marco
11:47
created

QueryException::invalidLiteral()   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 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 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Query;
6
7
use Doctrine\ORM\Mapping\AssociationMetadata;
8
use Doctrine\ORM\ORMException;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\ORMException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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