Completed
Push — ezp-31420-merge-up ( ec14fb...141a64 )
by
unknown
40:13 queued 27:42
created

DoctrineExpression::basicMath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Persistence\Doctrine;
8
9
use eZ\Publish\Core\Persistence\Database\Expression;
10
use Doctrine\DBAL\Connection;
11
use eZ\Publish\Core\Persistence\Database\QueryException;
12
13
/**
14
 * Class DoctrineExpression.
15
 *
16
 * @deprecated Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection)
17
 *             it provides richer and more powerful DB abstraction which is also easier to use.
18
 */
19
class DoctrineExpression implements Expression
0 ignored issues
show
Deprecated Code introduced by
The interface eZ\Publish\Core\Persistence\Database\Expression has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
20
{
21
    /** @var \Doctrine\DBAL\Connection */
22
    private $connection;
23
24
    /** @var \Doctrine\DBAL\Platforms\AbstractPlatform */
25
    private $platform;
26
27
    public function __construct(Connection $connection)
28
    {
29
        $this->connection = $connection;
30
        $this->platform = $connection->getDatabasePlatform();
31
    }
32
33
    /**
34
     * Returns the SQL to bind logical expressions together using a logical or.
35
     *
36
     * lOr() accepts an arbitrary number of parameters. Each parameter
37
     * must contain a logical expression or an array with logical expressions.
38
     *
39
     * Example:
40
     * <code>
41
     * $q = $dbHandler->createSelectQuery();
42
     * $e = $q->expr;
43
     * $q->select( '*' )->from( 'table' )
44
     *                  ->where( $e->lOr( $e->eq( 'id', $q->bindValue( 1 ) ),
45
     *                                    $e->eq( 'id', $q->bindValue( 2 ) ) ) );
46
     * </code>
47
     *
48
     * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters.
49
     *
50
     * @return string a logical expression
51
     */
52
    public function lOr()
53
    {
54
        $args = func_get_args();
55
56
        return $this->combine($args, ' OR ');
57
    }
58
59
    /**
60
     * Combine an array of expression by OR/AND.
61
     *
62
     * @param array $args
63
     * @param string $by
64
     *
65
     * @return string
66
     */
67
    private function combine(array $args, $by)
68
    {
69
        $args = $this->arrayFlatten($args);
70
71
        if (count($args) < 1) {
72
            throw new QueryException(
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\Persiste...Database\QueryException has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
73
                "Expression '{$by}' expected at least 1 argument, but none were provided."
74
            );
75
        }
76
77
        if (count($args) === 1) {
78
            return $args[0];
79
        }
80
81
        return '( ' . implode($by, $args) . ' )';
82
    }
83
84
    /**
85
     * Returns the SQL to bind logical expressions together using a logical and.
86
     *
87
     * lAnd() accepts an arbitrary number of parameters. Each parameter
88
     * must contain a logical expression or an array with logical expressions.
89
     *
90
     * Example:
91
     * <code>
92
     * $q = $dbHandler->createSelectQuery();
93
     * $e = $q->expr;
94
     * $q->select( '*' )->from( 'table' )
95
     *                  ->where( $e->lAnd( $e->eq( 'id', $q->bindValue( 1 ) ),
96
     *                                     $e->eq( 'id', $q->bindValue( 2 ) ) ) );
97
     * </code>
98
     *
99
     * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters.
100
     *
101
     * @return string a logical expression
102
     */
103
    public function lAnd()
104
    {
105
        $args = func_get_args();
106
107
        return $this->combine($args, ' AND ');
108
    }
109
110
    /**
111
     * Returns the SQL for a logical not, negating the $expression.
112
     *
113
     * Example:
114
     * <code>
115
     * $q = $dbHandler->createSelectQuery();
116
     * $e = $q->expr;
117
     * $q->select( '*' )->from( 'table' )
118
     *                  ->where( $e->eq( 'id', $e->not( 'null' ) ) );
119
     * </code>
120
     *
121
     * @param string $expression
122
     *
123
     * @return string a logical expression
124
     */
125
    public function not($expression)
126
    {
127
        return "NOT ( {$expression} )";
128
    }
129
130
    /**
131
     * Returns the SQL to add values or expressions together.
132
     *
133
     * add() accepts an arbitrary number of parameters. Each parameter
134
     * must contain a value or an expression or an array with values or
135
     * expressions.
136
     *
137
     * Example:
138
     * <code>
139
     * $q = $dbHandler->createSelectQuery();
140
     * $q->select( '*' )->from( 'table' )
141
     *                  ->where( $q->expr->add( 'id', 2 )  );
142
     * </code>
143
     *
144
     * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters.
145
     *
146
     * @param string|array(string) $...
0 ignored issues
show
Documentation introduced by
The doc-type string|array(string) could not be parsed: Expected "|" or "end of type", but got "(" at position 12. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
Bug introduced by
There is no parameter named $.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
147
     *
148
     * @return string an expression
149
     */
150
    public function add()
151
    {
152
        $args = func_get_args();
153
154
        return $this->basicMath('+', $args);
155
    }
156
157
    /**
158
     * Returns the SQL to subtract values or expressions from eachother.
159
     *
160
     * subtract() accepts an arbitrary number of parameters. Each parameter
161
     * must contain a value or an expression or an array with values or
162
     * expressions.
163
     *
164
     * Example:
165
     * <code>
166
     * $q = $dbHandler->createSelectQuery();
167
     * $q->select( '*' )->from( 'table' )
168
     *                  ->where( $q->expr->subtract( 'id', 2 )  );
169
     * </code>
170
     *
171
     * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters.
172
     *
173
     * @param string|array(string) $...
0 ignored issues
show
Documentation introduced by
The doc-type string|array(string) could not be parsed: Expected "|" or "end of type", but got "(" at position 12. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
Bug introduced by
There is no parameter named $.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
174
     *
175
     * @return string an expression
176
     */
177
    public function sub()
178
    {
179
        $args = func_get_args();
180
181
        return $this->basicMath('-', $args);
182
    }
183
184
    /**
185
     * Returns the SQL to multiply values or expressions by eachother.
186
     *
187
     * multiply() accepts an arbitrary number of parameters. Each parameter
188
     * must contain a value or an expression or an array with values or
189
     * expressions.
190
     *
191
     * Example:
192
     * <code>
193
     * $q = $dbHandler->createSelectQuery();
194
     * $q->select( '*' )->from( 'table' )
195
     *                  ->where( $q->expr->multiply( 'id', 2 )  );
196
     * </code>
197
     *
198
     * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters.
199
     *
200
     * @param string|array(string) $...
0 ignored issues
show
Documentation introduced by
The doc-type string|array(string) could not be parsed: Expected "|" or "end of type", but got "(" at position 12. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
Bug introduced by
There is no parameter named $.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
201
     *
202
     * @return string an expression
203
     */
204
    public function mul()
205
    {
206
        $args = func_get_args();
207
208
        return $this->basicMath('*', $args);
209
    }
210
211
    /**
212
     * Returns the SQL to divide values or expressions by eachother.
213
     *
214
     * divide() accepts an arbitrary number of parameters. Each parameter
215
     * must contain a value or an expression or an array with values or
216
     * expressions.
217
     *
218
     * Example:
219
     * <code>
220
     * $q = $dbHandler->createSelectQuery();
221
     * $q->select( '*' )->from( 'table' )
222
     *                  ->where( $q->expr->divide( 'id', 2 )  );
223
     * </code>
224
     *
225
     * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters.
226
     *
227
     * @param string|array(string) $...
0 ignored issues
show
Documentation introduced by
The doc-type string|array(string) could not be parsed: Expected "|" or "end of type", but got "(" at position 12. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
Bug introduced by
There is no parameter named $.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
228
     *
229
     * @return string an expression
230
     */
231
    public function div()
232
    {
233
        $args = func_get_args();
234
235
        return $this->basicMath('/', $args);
236
    }
237
238
    /**
239
     * Returns the SQL to check if two values are equal.
240
     *
241
     * Example:
242
     * <code>
243
     * $q = $dbHandler->createSelectQuery();
244
     * $q->select( '*' )->from( 'table' )
245
     *                  ->where( $q->expr->eq( 'id', $q->bindValue( 1 ) ) );
246
     * </code>
247
     *
248
     * @param string $value1 logical expression to compare
249
     * @param string $value2 logical expression to compare with
250
     *
251
     * @return string logical expression
252
     */
253
    public function eq($value1, $value2)
254
    {
255
        return "{$value1} = {$value2}";
256
    }
257
258
    /**
259
     * Returns the SQL to check if two values are unequal.
260
     *
261
     * Example:
262
     * <code>
263
     * $q = $dbHandler->createSelectQuery();
264
     * $q->select( '*' )->from( 'table' )
265
     *                  ->where( $q->expr->neq( 'id', $q->bindValue( 1 ) ) );
266
     * </code>
267
     *
268
     * @param string $value1 logical expression to compare
269
     * @param string $value2 logical expression to compare with
270
     *
271
     * @return string logical expression
272
     */
273
    public function neq($value1, $value2)
274
    {
275
        return "{$value1} <> {$value2}";
276
    }
277
278
    /**
279
     * Returns the SQL to check if one value is greater than another value.
280
     *
281
     * Example:
282
     * <code>
283
     * $q = $dbHandler->createSelectQuery();
284
     * $q->select( '*' )->from( 'table' )
285
     *                  ->where( $q->expr->gt( 'id', $q->bindValue( 1 ) ) );
286
     * </code>
287
     *
288
     * @param string $value1 logical expression to compare
289
     * @param string $value2 logical expression to compare with
290
     *
291
     * @return string logical expression
292
     */
293
    public function gt($value1, $value2)
294
    {
295
        return "{$value1} > {$value2}";
296
    }
297
298
    /**
299
     * Returns the SQL to check if one value is greater than or equal to
300
     * another value.
301
     *
302
     * Example:
303
     * <code>
304
     * $q = $dbHandler->createSelectQuery();
305
     * $q->select( '*' )->from( 'table' )
306
     *                  ->where( $q->expr->gte( 'id', $q->bindValue( 1 ) ) );
307
     * </code>
308
     *
309
     * @param string $value1 logical expression to compare
310
     * @param string $value2 logical expression to compare with
311
     *
312
     * @return string logical expression
313
     */
314
    public function gte($value1, $value2)
315
    {
316
        return "{$value1} >= {$value2}";
317
    }
318
319
    /**
320
     * Returns the SQL to check if one value is less than another value.
321
     *
322
     * Example:
323
     * <code>
324
     * $q = $dbHandler->createSelectQuery();
325
     * $q->select( '*' )->from( 'table' )
326
     *                  ->where( $q->expr->lt( 'id', $q->bindValue( 1 ) ) );
327
     * </code>
328
     *
329
     * @param string $value1 logical expression to compare
330
     * @param string $value2 logical expression to compare with
331
     *
332
     * @return string logical expression
333
     */
334
    public function lt($value1, $value2)
335
    {
336
        return "{$value1} < {$value2}";
337
    }
338
339
    /**
340
     * Returns the SQL to check if one value is less than or equal to
341
     * another value.
342
     *
343
     * Example:
344
     * <code>
345
     * $q = $dbHandler->createSelectQuery();
346
     * $q->select( '*' )->from( 'table' )
347
     *                  ->where( $q->expr->lte( 'id', $q->bindValue( 1 ) ) );
348
     * </code>
349
     *
350
     * @param string $value1 logical expression to compare
351
     * @param string $value2 logical expression to compare with
352
     *
353
     * @return string logical expression
354
     */
355
    public function lte($value1, $value2)
356
    {
357
        return "{$value1} <= {$value2}";
358
    }
359
360
    /**
361
     * Returns the SQL to check if a value is one in a set of
362
     * given values..
363
     *
364
     * in() accepts an arbitrary number of parameters. The first parameter
365
     * must always specify the value that should be matched against. Successive
366
     * parameters must contain a logical expression or an array with logical
367
     * expressions.  These expressions will be matched against the first
368
     * parameter.
369
     *
370
     * Example:
371
     * <code>
372
     * $q->select( '*' )->from( 'table' )
373
     *                  ->where( $q->expr->in( 'id', 1, 2, 3 ) );
374
     * </code>
375
     *
376
     * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with less than two
377
     *         parameters.
378
     * @throws \eZ\Publish\Core\Persistence\Database\QueryException if the 2nd parameter is an
379
     *         empty array.
380
     *
381
     * @param string $column the value that should be matched against
382
     * @param string|array(string) $... values that will be matched against $column
0 ignored issues
show
Documentation introduced by
The doc-type string|array(string) could not be parsed: Expected "|" or "end of type", but got "(" at position 12. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
Bug introduced by
There is no parameter named $.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
383
     *
384
     * @return string logical expression
385
     */
386
    public function in($column)
387
    {
388
        $args = func_get_args();
389
390
        if (count($args) < 2) {
391
            throw new QueryException('Two or more parameters are expected for in()');
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\Persiste...Database\QueryException has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
392
        }
393
394
        if (is_array($args[1])) {
395
            $values = array_values($args[1]);
396
        } else {
397
            $values = array_slice($args, 1);
398
        }
399
400
        // Special handling of sub selects to avoid double braces
401
        if (count($values) === 1 && $values[0] instanceof SubselectDoctrineQuery) {
402
            return "{$column} IN " . $values[0]->getQuery();
403
        }
404
405
        if (count($values) == 0) {
406
            throw new QueryException('At least one element is required as value.');
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\Persiste...Database\QueryException has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
407
        }
408
409
        foreach ($values as $key => $value) {
410
            switch (true) {
411
                case $value instanceof SubselectDoctrineQuery:
412
                    $values[$key] = $value->getQuery();
413
                    break;
414
                case is_int($value):
415
                case is_float($value):
416
                    $values[$key] = (string)$value;
417
                    break;
418
                default:
419
                    $values[$key] = $this->connection->quote($value);
420
            }
421
        }
422
423
        return "{$column} IN ( " . implode(', ', $values) . ' )';
424
    }
425
426
    /**
427
     * Returns SQL that checks if a expression is null.
428
     *
429
     * Example:
430
     * <code>
431
     * $q = $dbHandler->createSelectQuery();
432
     * $q->select( '*' )->from( 'table' )
433
     *                  ->where( $q->expr->isNull( 'id' ) );
434
     * </code>
435
     *
436
     * @param string $expression the expression that should be compared to null
437
     *
438
     * @return string logical expression
439
     */
440
    public function isNull($expression)
441
    {
442
        return "{$expression} IS NULL";
443
    }
444
445
    /**
446
     * Returns SQL that checks if an expression evaluates to a value between
447
     * two values.
448
     *
449
     * The parameter $expression is checked if it is between $value1 and $value2.
450
     *
451
     * Note: There is a slight difference in the way BETWEEN works on some databases.
452
     * http://www.w3schools.com/sql/sql_between.asp. If you want complete database
453
     * independence you should avoid using between().
454
     *
455
     * Example:
456
     * <code>
457
     * $q = $dbHandler->createSelectQuery();
458
     * $q->select( '*' )->from( 'table' )
459
     *                  ->where( $q->expr->between( 'id', $q->bindValue( 1 ), $q->bindValue( 5 ) ) );
460
     * </code>
461
     *
462
     * @param string $expression the value to compare to
463
     * @param string $value1 the lower value to compare with
464
     * @param string $value2 the higher value to compare with
465
     *
466
     * @return string logical expression
467
     */
468
    public function between($expression, $value1, $value2)
469
    {
470
        return "{$expression} BETWEEN {$value1} AND {$value2}";
471
    }
472
473
    /**
474
     * Match a partial string in a column.
475
     *
476
     * Like will look for the pattern in the column given. Like accepts
477
     * the wildcards '_' matching a single character and '%' matching
478
     * any number of characters.
479
     *
480
     * @param string $expression the name of the expression to match on
481
     * @param string $pattern the pattern to match with.
482
     */
483
    public function like($expression, $pattern)
484
    {
485
        return "{$expression} LIKE {$pattern}";
486
    }
487
488
    /**
489
     * Returns the average value of a column.
490
     *
491
     * @param string $column the column to use
492
     *
493
     * @return string
494
     */
495
    public function avg($column)
496
    {
497
        return "AVG( {$column} )";
498
    }
499
500
    /**
501
     * Returns the number of rows (without a NULL value) of a column.
502
     *
503
     * If a '*' is used instead of a column the number of selected rows
504
     * is returned.
505
     *
506
     * @param string $column the column to use
507
     *
508
     * @return string
509
     */
510
    public function count($column)
511
    {
512
        return "COUNT( {$column} )";
513
    }
514
515
    /**
516
     * Returns the highest value of a column.
517
     *
518
     * @param string $column the column to use
519
     *
520
     * @return string
521
     */
522
    public function max($column)
523
    {
524
        return "MAX( {$column} )";
525
    }
526
527
    /**
528
     * Returns the lowest value of a column.
529
     *
530
     * @param string $column the column to use
531
     *
532
     * @return string
533
     */
534
    public function min($column)
535
    {
536
        return "MIN( {$column} )";
537
    }
538
539
    /**
540
     * Returns the total sum of a column.
541
     *
542
     * @param string $column the column to use
543
     *
544
     * @return string
545
     */
546
    public function sum($column)
547
    {
548
        return "SUM( {$column} )";
549
    }
550
551
    /**
552
     * Returns the length of text field $column.
553
     *
554
     * @param string $column
555
     *
556
     * @return string
557
     */
558
    public function length($column)
559
    {
560
        return $this->platform->getLengthExpression($column);
561
    }
562
563
    /**
564
     * Rounds a numeric field to the number of decimals specified.
565
     *
566
     * @param string $column
567
     * @param int $decimals
568
     *
569
     * @return string
570
     */
571
    public function round($column, $decimals)
572
    {
573
        return $this->platform->getRoundExpression($column, $decimals);
574
    }
575
576
    /**
577
     * Returns the remainder of the division operation
578
     * $expression1 / $expression2.
579
     *
580
     * @param string $expression1
581
     * @param string $expression2
582
     *
583
     * @return string
584
     */
585
    public function mod($expression1, $expression2)
586
    {
587
        return $this->platform->getModExpression($expression1, $expression2);
588
    }
589
590
    /**
591
     * Returns the current system date and time in the database internal
592
     * format.
593
     *
594
     * @return string
595
     */
596
    public function now()
597
    {
598
        return $this->platform->getNowExpression();
599
    }
600
601
    /**
602
     * Returns part of a string.
603
     *
604
     * Note: Not SQL92, but common functionality.
605
     *
606
     * @param string $value the target $value the string or the string column.
607
     * @param int $from extract from this characeter.
608
     * @param int $len extract this amount of characters.
609
     *
610
     * @return string sql that extracts part of a string.
611
     */
612
    public function subString($value, $from, $len = null)
613
    {
614
        return $this->platform->getSubstringExpression($value, $from, $len);
615
    }
616
617
    /**
618
     * Returns a series of strings concatinated.
619
     *
620
     * concat() accepts an arbitrary number of parameters. Each parameter
621
     * must contain an expression or an array with expressions.
622
     *
623
     * @param string|array(string) $... strings that will be concatinated.
0 ignored issues
show
Documentation introduced by
The doc-type string|array(string) could not be parsed: Expected "|" or "end of type", but got "(" at position 12. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
Bug introduced by
There is no parameter named $.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
624
     */
625
    public function concat()
626
    {
627
        $args = func_get_args();
628
629
        return call_user_func_array([$this->platform, 'getConcatExpression'], $args);
630
    }
631
632
    /**
633
     * Returns the SQL to locate the position of the first occurrence of a substring.
634
     *
635
     * @param string $substr
636
     * @param string $value
637
     *
638
     * @return string
639
     */
640
    public function position($substr, $value)
641
    {
642
        return $this->platform->getLocateExpression($value, $substr);
643
    }
644
645
    /**
646
     * Returns the SQL to change all characters to lowercase.
647
     *
648
     * @param string $value
649
     *
650
     * @return string
651
     */
652
    public function lower($value)
653
    {
654
        return $this->platform->getLowerExpression($value);
655
    }
656
657
    /**
658
     * Returns the SQL to change all characters to uppercase.
659
     *
660
     * @param string $value
661
     *
662
     * @return string
663
     */
664
    public function upper($value)
665
    {
666
        return $this->platform->getUpperExpression($value);
667
    }
668
669
    /**
670
     * Returns the SQL that performs the bitwise AND on two values.
671
     *
672
     * @param string $value1
673
     * @param string $value2
674
     *
675
     * @return string
676
     */
677
    public function bitAnd($value1, $value2)
678
    {
679
        return $this->platform->getBitAndComparisonExpression($value1, $value2);
680
    }
681
682
    /**
683
     * Returns the SQL that performs the bitwise OR on two values.
684
     *
685
     * @param string $value1
686
     * @param string $value2
687
     *
688
     * @return string
689
     */
690
    public function bitOr($value1, $value2)
691
    {
692
        return $this->platform->getBitOrComparisonExpression($value1, $value2);
693
    }
694
695
    /**
696
     * Returns a searched CASE statement.
697
     *
698
     * Accepts an arbitrary number of parameters.
699
     * The first parameter (array) must always be specified, the last
700
     * parameter (string) specifies the ELSE result.
701
     *
702
     * Example:
703
     * <code>
704
     * $q = $dbHandler->createSelectQuery();
705
     * $q->select(
706
     *      $q->expr->searchedCase(
707
     *            array( $q->expr->gte( 'column1', 20 ), 'column1' )
708
     *          , array( $q->expr->gte( 'column2', 50 ), 'column2' )
709
     *          , 'column3'
710
     *      )
711
     *  )
712
     *     ->from( 'table' );
713
     * </code>
714
     *
715
     * @throws \eZ\Publish\Core\Persistence\Database\QueryException
716
     *
717
     * @return string
718
     */
719
    public function searchedCase()
720
    {
721
        $args = func_get_args();
722
723
        if (count($args) === 0) {
724
            throw new QueryException('At least one parameter is expected in searchedCase()');
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\Persiste...Database\QueryException has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
725
        }
726
727
        $expr = ' CASE';
728
        foreach ($args as $arg) {
729
            if (is_array($arg) && count($arg) == 2) {
730
                $column1 = $arg[0];
731
                $column2 = $arg[1];
732
                $expr .= " WHEN {$column1} THEN {$column2}";
733
            } elseif (is_scalar($arg)) {
734
                $column = $arg;
735
                $expr .= " ELSE {$column}";
736
            }
737
        }
738
        $expr .= ' END ';
739
740
        return $expr;
741
    }
742
743
    /**
744
     * Returns the SQL to perform the same mathematical operation over an array
745
     * of values or expressions.
746
     *
747
     * basicMath() accepts an arbitrary number of parameters. Each parameter
748
     * must contain a value or an expression or an array with values or
749
     * expressions.
750
     *
751
     * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters.
752
     *
753
     * @param string $type the type of operation, can be '+', '-', '*' or '/'.
754
     * @param string|array(string) $...
0 ignored issues
show
Documentation introduced by
The doc-type string|array(string) could not be parsed: Expected "|" or "end of type", but got "(" at position 12. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
Bug introduced by
There is no parameter named $.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
755
     *
756
     * @return string an expression
757
     */
758
    private function basicMath($type)
759
    {
760
        $args = func_get_args();
761
        $elements = $this->arrayFlatten(array_slice($args, 1));
762
        if (count($elements) < 1) {
763
            throw new QueryException(
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\Persiste...Database\QueryException has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
764
                "The operation '{$type}' expected at least 1 argument but none provided."
765
            );
766
        }
767
        if (count($elements) == 1) {
768
            return $elements[0];
769
        } else {
770
            return '( ' . implode(" $type ", $elements) . ' )';
771
        }
772
    }
773
774
    /**
775
     * Returns all the elements in $array as one large single dimensional array.
776
     *
777
     * @param array $array
778
     *
779
     * @return array
780
     */
781
    private function arrayFlatten(array $array)
782
    {
783
        $flat = [];
784
        foreach ($array as $arg) {
785
            switch (gettype($arg)) {
786
                case 'array':
787
                    $flat = array_merge($flat, $arg);
788
                    break;
789
790
                default:
791
                    $flat[] = $arg;
792
                    break;
793
            }
794
        }
795
796
        return $flat;
797
    }
798
}
799