Skip to content

Commit

Permalink
Replaced func_get_args() with variadic arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jan 21, 2020
1 parent 22854d2 commit 3c679c3
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 201 deletions.
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Upgrade to 3.0

## BC BREAK: Changes in the QueryBuilder API.

1. The `select()`, `addSelect()`, `groupBy()` and `addGroupBy()` methods no longer accept an array of arguments. Pass each expression as an individual argument or expand an array of expressions using the `...` operator.
2. The `select()`, `addSelect()`, `groupBy()` and `addGroupBy()` methods no longer ignore the first argument if it's empty.
3. The `addSelect()` method can be no longer called without arguments.

## BC BREAK: `QueryBuilder::insert()`, `update()` and `delete()` signatures changed

These methods now require the `$table` parameter, and do not support aliases anymore.
Expand Down
33 changes: 14 additions & 19 deletions lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
namespace Doctrine\DBAL\Query\Expression;

use Doctrine\DBAL\Connection;
use function func_get_arg;
use function func_get_args;
use function func_num_args;
use function implode;
use function sprintf;

Expand Down Expand Up @@ -41,37 +38,35 @@ public function __construct(Connection $connection)
}

/**
* Creates a conjunction of the given boolean expressions.
* Creates a conjunction of the given expressions.
*
* Example:
*
* [php]
* // (u.type = ?) AND (u.role = ?)
* $expr->andX('u.type = ?', 'u.role = ?'));
*
* @param mixed $x Optional clause. Defaults = null, but requires
* at least one defined when converting to string.
* @param string|CompositeExpression ...$expressions Requires at least one defined when converting to string.
*/
public function andX($x = null) : CompositeExpression
public function andX(...$expressions) : CompositeExpression
{
return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
return new CompositeExpression(CompositeExpression::TYPE_AND, $expressions);
}

/**
* Creates a disjunction of the given boolean expressions.
* Creates a disjunction of the given expressions.
*
* Example:
*
* [php]
* // (u.type = ?) OR (u.role = ?)
* $qb->where($qb->expr()->orX('u.type = ?', 'u.role = ?'));
*
* @param mixed $x Optional clause. Defaults = null, but requires
* at least one defined when converting to string.
* @param string|CompositeExpression ...$expressions Requires at least one defined when converting to string.
*/
public function orX($x = null) : CompositeExpression
public function orX(...$expressions) : CompositeExpression
{
return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
return new CompositeExpression(CompositeExpression::TYPE_OR, $expressions);
}

/**
Expand Down Expand Up @@ -210,27 +205,27 @@ public function isNotNull(string $x) : string
}

/**
* Creates a LIKE() comparison expression with the given arguments.
* Creates a LIKE comparison expression.
*
* @param string $x Field in string format to be inspected by LIKE() comparison.
* @param mixed $y Argument to be used in LIKE() comparison.
*/
public function like(string $x, $y/*, ?string $escapeChar = null */) : string
public function like(string $x, $y, ?string $escapeChar = null) : string
{
return $this->comparison($x, 'LIKE', $y) .
(func_num_args() >= 3 ? sprintf(' ESCAPE %s', func_get_arg(2)) : '');
($escapeChar !== null ? sprintf(' ESCAPE %s', $escapeChar) : '');
}

/**
* Creates a NOT LIKE() comparison expression with the given arguments.
* Creates a NOT LIKE comparison expression
*
* @param string $x Field in string format to be inspected by NOT LIKE() comparison.
* @param mixed $y Argument to be used in NOT LIKE() comparison.
*/
public function notLike(string $x, $y/*, ?string $escapeChar = null */) : string
public function notLike(string $x, $y, ?string $escapeChar = null) : string
{
return $this->comparison($x, 'NOT LIKE', $y) .
(func_num_args() >= 3 ? sprintf(' ESCAPE %s', func_get_arg(2)) : '');
($escapeChar !== null ? sprintf(' ESCAPE %s', $escapeChar) : '');
}

/**
Expand Down
Loading

0 comments on commit 3c679c3

Please sign in to comment.