Failed Conditions
Pull Request — master (#6143)
by Luís
10:34
created

QueryException::dqlError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ORM\Query;
21
22
use Doctrine\ORM\Query\AST\PathExpression;
23
24
/**
25
 * Description of QueryException.
26
 *
27
 * @link    www.doctrine-project.org
28
 * @since   2.0
29
 * @author  Guilherme Blanco <[email protected]>
30
 * @author  Jonathan Wage <[email protected]>
31
 * @author  Roman Borschel <[email protected]>
32
 * @author  Benjamin Eberlei <[email protected]>
33
 */
34
class QueryException extends \Doctrine\ORM\ORMException
35
{
36
    /**
37
     * @param string $dql
38
     *
39
     * @return QueryException
40
     */
41 52
    public static function dqlError($dql)
42
    {
43 52
        return new self($dql);
44
    }
45
46
    /**
47
     * @param string          $message
48
     * @param \Exception|null $previous
49
     *
50
     * @return QueryException
51
     */
52 18
    public static function syntaxError($message, $previous = null)
53
    {
54 18
        return new self('[Syntax Error] ' . $message, 0, $previous);
55
    }
56
57
    /**
58
     * @param string          $message
59
     * @param \Exception|null $previous
60
     *
61
     * @return QueryException
62
     */
63 35
    public static function semanticalError($message, $previous = null)
64
    {
65 35
        return new self('[Semantical Error] ' . $message, 0, $previous);
66
    }
67
68
    /**
69
     * @return QueryException
70
     */
71
    public static function invalidLockMode()
72
    {
73
        return new self('Invalid lock mode hint provided.');
74
    }
75
76
    /**
77
     * @param string $expected
78
     * @param string $received
79
     *
80
     * @return QueryException
81
     */
82
    public static function invalidParameterType($expected, $received)
83
    {
84
        return new self('Invalid parameter type, ' . $received . ' given, but ' . $expected . ' expected.');
85
    }
86
87
    /**
88
     * @param string $pos
89
     *
90
     * @return QueryException
91
     */
92
    public static function invalidParameterPosition($pos)
93
    {
94
        return new self('Invalid parameter position: ' . $pos);
95
    }
96
97
    /**
98
     * @param integer $expected
99
     * @param integer $received
100
     *
101
     * @return QueryException
102
     */
103 1
    public static function tooManyParameters($expected, $received)
104
    {
105 1
        return new self('Too many parameters: the query defines ' . $expected . ' parameters and you bound ' . $received);
106
    }
107
108
    /**
109
     * @param integer $expected
110
     * @param integer $received
111
     *
112
     * @return QueryException
113
     */
114 1
    public static function tooFewParameters($expected, $received)
115
    {
116 1
        return new self('Too few parameters: the query defines ' . $expected . ' parameters but you only bound ' . $received);
117
    }
118
119
    /**
120
     * @param string $value
121
     *
122
     * @return QueryException
123
     */
124 2
    public static function invalidParameterFormat($value)
125
    {
126 2
        return new self('Invalid parameter format, '.$value.' given, but :<name> or ?<num> expected.');
127
    }
128
129
    /**
130
     * @param string $key
131
     *
132
     * @return QueryException
133
     */
134 1
    public static function unknownParameter($key)
135
    {
136 1
        return new self("Invalid parameter: token ".$key." is not defined in the query.");
137
    }
138
139
    /**
140
     * @return QueryException
141
     */
142
    public static function parameterTypeMismatch()
143
    {
144
        return new self("DQL Query parameter and type numbers mismatch, but have to be exactly equal.");
145
    }
146
147
    /**
148
     * @param object $pathExpr
149
     *
150
     * @return QueryException
151
     */
152
    public static function invalidPathExpression($pathExpr)
153
    {
154
        return new self(
155
            "Invalid PathExpression '" . $pathExpr->identificationVariable . "." . $pathExpr->field . "'."
156
        );
157
    }
158
159
    /**
160
     * @param string $literal
161
     *
162
     * @return QueryException
163
     */
164
    public static function invalidLiteral($literal)
165
    {
166
        return new self("Invalid literal '$literal'");
167
    }
168
169
    /**
170
     * @param array $assoc
171
     *
172
     * @return QueryException
173
     */
174 View Code Duplication
    public static function iterateWithFetchJoinCollectionNotAllowed($assoc)
175
    {
176
        return new self(
177
            "Invalid query operation: Not allowed to iterate over fetch join collections ".
178
            "in class ".$assoc['sourceEntity']." association ".$assoc['fieldName']
179
        );
180
    }
181
182
    /**
183
     * @return QueryException
184
     */
185
    public static function partialObjectsAreDangerous()
186
    {
187
        return new self(
188
            "Loading partial objects is dangerous. Fetch full objects or consider " .
189
            "using a different fetch mode. If you really want partial objects, " .
190
            "set the doctrine.forcePartialLoad query hint to TRUE."
191
        );
192
    }
193
194
    /**
195
     * @param array $assoc
196
     *
197
     * @return QueryException
198
     */
199
    public static function overwritingJoinConditionsNotYetSupported($assoc)
200
    {
201
        return new self(
202
            "Unsupported query operation: It is not yet possible to overwrite the join ".
203
            "conditions in class ".$assoc['sourceEntityName']." association ".$assoc['fieldName'].". ".
204
            "Use WITH to append additional join conditions to the association."
205
        );
206
    }
207
208
    /**
209
     * @param PathExpression $pathExpr
210
     *
211
     * @return QueryException
212
     */
213 2
    public static function associationPathInverseSideNotSupported(PathExpression $pathExpr)
214
    {
215 2
        return new self(
216
            'A single-valued association path expression to an inverse side is not supported in DQL queries. ' .
217 2
            'Instead of "' . $pathExpr->identificationVariable . '.' . $pathExpr->field . '" use an explicit join.'
218
        );
219
    }
220
221
    /**
222
     * @param array $assoc
223
     *
224
     * @return QueryException
225
     */
226 2 View Code Duplication
    public static function iterateWithFetchJoinNotAllowed($assoc)
227
    {
228 2
        return new self(
229 2
            "Iterate with fetch join in class " . $assoc['sourceEntity'] .
230 2
            " using association " . $assoc['fieldName'] . " not allowed."
231
        );
232
    }
233
234
    /**
235
     * @return QueryException
236
     */
237 1
    public static function associationPathCompositeKeyNotSupported()
238
    {
239 1
        return new self(
240
            "A single-valued association path expression to an entity with a composite primary ".
241
            "key is not supported. Explicitly name the components of the composite primary key ".
242 1
            "in the query."
243
        );
244
    }
245
246
    /**
247
     * @param string $className
248
     * @param string $rootClass
249
     *
250
     * @return QueryException
251
     */
252 1
    public static function instanceOfUnrelatedClass($className, $rootClass)
253
    {
254 1
        return new self("Cannot check if a child of '" . $rootClass . "' is instanceof '" . $className . "', " .
255 1
            "inheritance hierarchy does not exists between these two classes.");
256
    }
257
258
    /**
259
     * @param string $dqlAlias
260
     *
261
     * @return QueryException
262
     */
263 1
    public static function invalidQueryComponent($dqlAlias)
264
    {
265 1
        return new self(
266 1
            "Invalid query component given for DQL alias '" . $dqlAlias . "', ".
267 1
            "requires 'metadata', 'parent', 'relation', 'map', 'nestingLevel' and 'token' keys."
268
        );
269
    }
270
}
271