Skip to content

Commit

Permalink
Merge pull request #3841 from morozov/issues/3825-NEXT
Browse files Browse the repository at this point in the history
Enforced argument and return types in QueryBuilder and ExpressionBuilder
  • Loading branch information
morozov authored Jan 22, 2020
2 parents 9728d99 + 7887880 commit 4d9a08c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
60 changes: 30 additions & 30 deletions lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public function orX(...$expressions) : CompositeExpression
/**
* Creates a comparison expression.
*
* @param mixed $x The left expression.
* @param string $operator One of the ExpressionBuilder::* constants.
* @param mixed $y The right expression.
* @param string $x The left expression.
* @param string $operator The comparison operator.
* @param string $y The right expression.
*/
public function comparison($x, string $operator, $y) : string
public function comparison(string $x, string $operator, string $y) : string
{
return $x . ' ' . $operator . ' ' . $y;
}
Expand All @@ -91,10 +91,10 @@ public function comparison($x, string $operator, $y) : string
* // u.id = ?
* $expr->eq('u.id', '?');
*
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param string $x The left expression.
* @param string $y The right expression.
*/
public function eq($x, $y) : string
public function eq(string $x, string $y) : string
{
return $this->comparison($x, self::EQ, $y);
}
Expand All @@ -108,10 +108,10 @@ public function eq($x, $y) : string
* // u.id <> 1
* $q->where($q->expr()->neq('u.id', '1'));
*
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param string $x The left expression.
* @param string $y The right expression.
*/
public function neq($x, $y) : string
public function neq(string $x, string $y) : string
{
return $this->comparison($x, self::NEQ, $y);
}
Expand All @@ -125,10 +125,10 @@ public function neq($x, $y) : string
* // u.id < ?
* $q->where($q->expr()->lt('u.id', '?'));
*
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param string $x The left expression.
* @param string $y The right expression.
*/
public function lt($x, $y) : string
public function lt(string $x, string $y) : string
{
return $this->comparison($x, self::LT, $y);
}
Expand All @@ -142,10 +142,10 @@ public function lt($x, $y) : string
* // u.id <= ?
* $q->where($q->expr()->lte('u.id', '?'));
*
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param string $x The left expression.
* @param string $y The right expression.
*/
public function lte($x, $y) : string
public function lte(string $x, string $y) : string
{
return $this->comparison($x, self::LTE, $y);
}
Expand All @@ -159,10 +159,10 @@ public function lte($x, $y) : string
* // u.id > ?
* $q->where($q->expr()->gt('u.id', '?'));
*
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param string $x The left expression.
* @param string $y The right expression.
*/
public function gt($x, $y) : string
public function gt(string $x, string $y) : string
{
return $this->comparison($x, self::GT, $y);
}
Expand All @@ -176,10 +176,10 @@ public function gt($x, $y) : string
* // u.id >= ?
* $q->where($q->expr()->gte('u.id', '?'));
*
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param string $x The left expression.
* @param string $y The right expression.
*/
public function gte($x, $y) : string
public function gte(string $x, string $y) : string
{
return $this->comparison($x, self::GTE, $y);
}
Expand Down Expand Up @@ -207,24 +207,24 @@ public function isNotNull(string $x) : string
/**
* 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.
* @param string $expression The expression to be inspected by the LIKE comparison
* @param string $pattern The pattern to compare against
*/
public function like(string $x, $y, ?string $escapeChar = null) : string
public function like(string $expression, string $pattern, ?string $escapeChar = null) : string
{
return $this->comparison($x, 'LIKE', $y) .
return $this->comparison($expression, 'LIKE', $pattern) .
($escapeChar !== null ? sprintf(' ESCAPE %s', $escapeChar) : '');
}

/**
* 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.
* @param string $expression The expression to be inspected by the NOT LIKE comparison
* @param string $pattern The pattern to compare against
*/
public function notLike(string $x, $y, ?string $escapeChar = null) : string
public function notLike(string $expression, string $pattern, ?string $escapeChar = null) : string
{
return $this->comparison($x, 'NOT LIKE', $y) .
return $this->comparison($expression, 'NOT LIKE', $pattern) .
($escapeChar !== null ? sprintf(' ESCAPE %s', $escapeChar) : '');
}

Expand Down
30 changes: 15 additions & 15 deletions lib/Doctrine/DBAL/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public function insert(string $table) : self
*
* @return $this This QueryBuilder instance.
*/
public function from(string $from, ?string $alias = null)
public function from(string $from, ?string $alias = null) : self
{
return $this->add('from', new From($from, $alias), true);
}
Expand All @@ -618,7 +618,7 @@ public function from(string $from, ?string $alias = null)
*
* @return $this This QueryBuilder instance.
*/
public function join(string $fromAlias, string $join, string $alias, ?string $condition = null)
public function join(string $fromAlias, string $join, string $alias, ?string $condition = null) : self
{
return $this->innerJoin($fromAlias, $join, $alias, $condition);
}
Expand All @@ -640,7 +640,7 @@ public function join(string $fromAlias, string $join, string $alias, ?string $co
*
* @return $this This QueryBuilder instance.
*/
public function innerJoin(string $fromAlias, string $join, string $alias, ?string $condition = null)
public function innerJoin(string $fromAlias, string $join, string $alias, ?string $condition = null) : self
{
return $this->add('join', [
$fromAlias => Join::inner($join, $alias, $condition),
Expand All @@ -664,7 +664,7 @@ public function innerJoin(string $fromAlias, string $join, string $alias, ?strin
*
* @return $this This QueryBuilder instance.
*/
public function leftJoin(string $fromAlias, string $join, string $alias, ?string $condition = null)
public function leftJoin(string $fromAlias, string $join, string $alias, ?string $condition = null) : self
{
return $this->add('join', [
$fromAlias => Join::left($join, $alias, $condition),
Expand All @@ -688,7 +688,7 @@ public function leftJoin(string $fromAlias, string $join, string $alias, ?string
*
* @return $this This QueryBuilder instance.
*/
public function rightJoin(string $fromAlias, string $join, string $alias, ?string $condition = null)
public function rightJoin(string $fromAlias, string $join, string $alias, ?string $condition = null) : self
{
return $this->add('join', [
$fromAlias => Join::right($join, $alias, $condition),
Expand All @@ -710,7 +710,7 @@ public function rightJoin(string $fromAlias, string $join, string $alias, ?strin
*
* @return $this This QueryBuilder instance.
*/
public function set(string $key, string $value)
public function set(string $key, string $value) : self
{
return $this->add('set', $key . ' = ' . $value, true);
}
Expand Down Expand Up @@ -742,7 +742,7 @@ public function set(string $key, string $value)
*
* @return $this This QueryBuilder instance.
*/
public function where($predicate, ...$predicates)
public function where($predicate, ...$predicates) : self
{
return $this->setPredicates('where', $predicate, ...$predicates);
}
Expand All @@ -766,7 +766,7 @@ public function where($predicate, ...$predicates)
*
* @return $this This QueryBuilder instance.
*/
public function andWhere($predicate, ...$predicates)
public function andWhere($predicate, ...$predicates) : self
{
return $this->appendPredicates('where', CompositeExpression::TYPE_AND, $predicate, ...$predicates);
}
Expand All @@ -790,7 +790,7 @@ public function andWhere($predicate, ...$predicates)
*
* @return $this This QueryBuilder instance.
*/
public function orWhere($predicate, ...$predicates)
public function orWhere($predicate, ...$predicates) : self
{
return $this->appendPredicates('where', CompositeExpression::TYPE_OR, $predicate, ...$predicates);
}
Expand Down Expand Up @@ -882,7 +882,7 @@ public function setValue(string $column, string $value) : self
*
* @return $this This QueryBuilder instance.
*/
public function values(array $values)
public function values(array $values) : self
{
return $this->add('values', $values);
}
Expand All @@ -896,7 +896,7 @@ public function values(array $values)
*
* @return $this This QueryBuilder instance.
*/
public function having($predicate, ...$predicates)
public function having($predicate, ...$predicates) : self
{
return $this->setPredicates('having', $predicate, ...$predicates);
}
Expand All @@ -910,7 +910,7 @@ public function having($predicate, ...$predicates)
*
* @return $this This QueryBuilder instance.
*/
public function andHaving($predicate, ...$predicates)
public function andHaving($predicate, ...$predicates) : self
{
return $this->appendPredicates('having', CompositeExpression::TYPE_AND, $predicate, ...$predicates);
}
Expand All @@ -924,7 +924,7 @@ public function andHaving($predicate, ...$predicates)
*
* @return $this This QueryBuilder instance.
*/
public function orHaving($predicate, ...$predicates)
public function orHaving($predicate, ...$predicates) : self
{
return $this->appendPredicates('having', CompositeExpression::TYPE_OR, $predicate, ...$predicates);
}
Expand Down Expand Up @@ -983,7 +983,7 @@ private function appendPredicates(string $clause, string $type, ...$predicates)
*
* @return $this This QueryBuilder instance.
*/
public function orderBy(string $sort, ?string $order = null)
public function orderBy(string $sort, ?string $order = null) : self
{
return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), false);
}
Expand All @@ -996,7 +996,7 @@ public function orderBy(string $sort, ?string $order = null)
*
* @return $this This QueryBuilder instance.
*/
public function addOrderBy(string $sort, ?string $order = null)
public function addOrderBy(string $sort, ?string $order = null) : self
{
return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), true);
}
Expand Down

0 comments on commit 4d9a08c

Please sign in to comment.