Unverified Commit 598bcfd7 authored by Jonathan H. Wage's avatar Jonathan H. Wage Committed by Sergei Morozov

Add proper types to Doctrine\DBAL\Query namespace.

parent 77d3dfa3
...@@ -41,7 +41,7 @@ class CompositeExpression implements Countable ...@@ -41,7 +41,7 @@ class CompositeExpression implements Countable
* @param string $type Instance type of composite expression. * @param string $type Instance type of composite expression.
* @param self[]|string[] $parts Composition of expressions to be joined on composite expression. * @param self[]|string[] $parts Composition of expressions to be joined on composite expression.
*/ */
public function __construct($type, array $parts = []) public function __construct(string $type, array $parts = [])
{ {
$this->type = $type; $this->type = $type;
...@@ -51,11 +51,11 @@ class CompositeExpression implements Countable ...@@ -51,11 +51,11 @@ class CompositeExpression implements Countable
/** /**
* Adds multiple parts to composite expression. * Adds multiple parts to composite expression.
* *
* @param self[]|string[] $parts * @param array<int, self|string> $parts
* *
* @return \Doctrine\DBAL\Query\Expression\CompositeExpression * @return $this
*/ */
public function addMultiple(array $parts = []) public function addMultiple(array $parts = []) : self
{ {
foreach ($parts as $part) { foreach ($parts as $part) {
$this->add($part); $this->add($part);
...@@ -67,11 +67,11 @@ class CompositeExpression implements Countable ...@@ -67,11 +67,11 @@ class CompositeExpression implements Countable
/** /**
* Adds an expression to composite expression. * Adds an expression to composite expression.
* *
* @param mixed $part * @param self|string $part
* *
* @return \Doctrine\DBAL\Query\Expression\CompositeExpression * @return $this
*/ */
public function add($part) public function add($part) : self
{ {
if (empty($part)) { if (empty($part)) {
return $this; return $this;
...@@ -88,20 +88,16 @@ class CompositeExpression implements Countable ...@@ -88,20 +88,16 @@ class CompositeExpression implements Countable
/** /**
* Retrieves the amount of expressions on composite expression. * Retrieves the amount of expressions on composite expression.
*
* @return int
*/ */
public function count() public function count() : int
{ {
return count($this->parts); return count($this->parts);
} }
/** /**
* Retrieves the string representation of this composite expression. * Retrieves the string representation of this composite expression.
*
* @return string
*/ */
public function __toString() public function __toString() : string
{ {
if ($this->count() === 1) { if ($this->count() === 1) {
return (string) $this->parts[0]; return (string) $this->parts[0];
...@@ -112,10 +108,8 @@ class CompositeExpression implements Countable ...@@ -112,10 +108,8 @@ class CompositeExpression implements Countable
/** /**
* Returns the type of this composite expression (AND/OR). * Returns the type of this composite expression (AND/OR).
*
* @return string
*/ */
public function getType() public function getType() : string
{ {
return $this->type; return $this->type;
} }
......
...@@ -51,10 +51,8 @@ class ExpressionBuilder ...@@ -51,10 +51,8 @@ class ExpressionBuilder
* *
* @param mixed $x Optional clause. Defaults = null, but requires * @param mixed $x Optional clause. Defaults = null, but requires
* at least one defined when converting to string. * at least one defined when converting to string.
*
* @return CompositeExpression
*/ */
public function andX($x = null) public function andX($x = null) : CompositeExpression
{ {
return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args()); return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
} }
...@@ -70,10 +68,8 @@ class ExpressionBuilder ...@@ -70,10 +68,8 @@ class ExpressionBuilder
* *
* @param mixed $x Optional clause. Defaults = null, but requires * @param mixed $x Optional clause. Defaults = null, but requires
* at least one defined when converting to string. * at least one defined when converting to string.
*
* @return CompositeExpression
*/ */
public function orX($x = null) public function orX($x = null) : CompositeExpression
{ {
return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args()); return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
} }
...@@ -84,10 +80,8 @@ class ExpressionBuilder ...@@ -84,10 +80,8 @@ class ExpressionBuilder
* @param mixed $x The left expression. * @param mixed $x The left expression.
* @param string $operator One of the ExpressionBuilder::* constants. * @param string $operator One of the ExpressionBuilder::* constants.
* @param mixed $y The right expression. * @param mixed $y The right expression.
*
* @return string
*/ */
public function comparison($x, $operator, $y) public function comparison($x, string $operator, $y) : string
{ {
return $x . ' ' . $operator . ' ' . $y; return $x . ' ' . $operator . ' ' . $y;
} }
...@@ -104,10 +98,8 @@ class ExpressionBuilder ...@@ -104,10 +98,8 @@ class ExpressionBuilder
* *
* @param mixed $x The left expression. * @param mixed $x The left expression.
* @param mixed $y The right expression. * @param mixed $y The right expression.
*
* @return string
*/ */
public function eq($x, $y) public function eq($x, $y) : string
{ {
return $this->comparison($x, self::EQ, $y); return $this->comparison($x, self::EQ, $y);
} }
...@@ -123,10 +115,8 @@ class ExpressionBuilder ...@@ -123,10 +115,8 @@ class ExpressionBuilder
* *
* @param mixed $x The left expression. * @param mixed $x The left expression.
* @param mixed $y The right expression. * @param mixed $y The right expression.
*
* @return string
*/ */
public function neq($x, $y) public function neq($x, $y) : string
{ {
return $this->comparison($x, self::NEQ, $y); return $this->comparison($x, self::NEQ, $y);
} }
...@@ -142,10 +132,8 @@ class ExpressionBuilder ...@@ -142,10 +132,8 @@ class ExpressionBuilder
* *
* @param mixed $x The left expression. * @param mixed $x The left expression.
* @param mixed $y The right expression. * @param mixed $y The right expression.
*
* @return string
*/ */
public function lt($x, $y) public function lt($x, $y) : string
{ {
return $this->comparison($x, self::LT, $y); return $this->comparison($x, self::LT, $y);
} }
...@@ -161,10 +149,8 @@ class ExpressionBuilder ...@@ -161,10 +149,8 @@ class ExpressionBuilder
* *
* @param mixed $x The left expression. * @param mixed $x The left expression.
* @param mixed $y The right expression. * @param mixed $y The right expression.
*
* @return string
*/ */
public function lte($x, $y) public function lte($x, $y) : string
{ {
return $this->comparison($x, self::LTE, $y); return $this->comparison($x, self::LTE, $y);
} }
...@@ -180,10 +166,8 @@ class ExpressionBuilder ...@@ -180,10 +166,8 @@ class ExpressionBuilder
* *
* @param mixed $x The left expression. * @param mixed $x The left expression.
* @param mixed $y The right expression. * @param mixed $y The right expression.
*
* @return string
*/ */
public function gt($x, $y) public function gt($x, $y) : string
{ {
return $this->comparison($x, self::GT, $y); return $this->comparison($x, self::GT, $y);
} }
...@@ -199,10 +183,8 @@ class ExpressionBuilder ...@@ -199,10 +183,8 @@ class ExpressionBuilder
* *
* @param mixed $x The left expression. * @param mixed $x The left expression.
* @param mixed $y The right expression. * @param mixed $y The right expression.
*
* @return string
*/ */
public function gte($x, $y) public function gte($x, $y) : string
{ {
return $this->comparison($x, self::GTE, $y); return $this->comparison($x, self::GTE, $y);
} }
...@@ -211,10 +193,8 @@ class ExpressionBuilder ...@@ -211,10 +193,8 @@ class ExpressionBuilder
* Creates an IS NULL expression with the given arguments. * Creates an IS NULL expression with the given arguments.
* *
* @param string $x The field in string format to be restricted by IS NULL. * @param string $x The field in string format to be restricted by IS NULL.
*
* @return string
*/ */
public function isNull($x) public function isNull(string $x) : string
{ {
return $x . ' IS NULL'; return $x . ' IS NULL';
} }
...@@ -223,10 +203,8 @@ class ExpressionBuilder ...@@ -223,10 +203,8 @@ class ExpressionBuilder
* Creates an IS NOT NULL expression with the given arguments. * Creates an IS NOT NULL expression with the given arguments.
* *
* @param string $x The field in string format to be restricted by IS NOT NULL. * @param string $x The field in string format to be restricted by IS NOT NULL.
*
* @return string
*/ */
public function isNotNull($x) public function isNotNull(string $x) : string
{ {
return $x . ' IS NOT NULL'; return $x . ' IS NOT NULL';
} }
...@@ -236,10 +214,8 @@ class ExpressionBuilder ...@@ -236,10 +214,8 @@ class ExpressionBuilder
* *
* @param string $x Field in string format to be inspected by LIKE() comparison. * @param string $x Field in string format to be inspected by LIKE() comparison.
* @param mixed $y Argument to be used in LIKE() comparison. * @param mixed $y Argument to be used in LIKE() comparison.
*
* @return string
*/ */
public function like($x, $y/*, ?string $escapeChar = null */) public function like(string $x, $y/*, ?string $escapeChar = null */) : string
{ {
return $this->comparison($x, 'LIKE', $y) . return $this->comparison($x, 'LIKE', $y) .
(func_num_args() >= 3 ? sprintf(' ESCAPE %s', func_get_arg(2)) : ''); (func_num_args() >= 3 ? sprintf(' ESCAPE %s', func_get_arg(2)) : '');
...@@ -250,10 +226,8 @@ class ExpressionBuilder ...@@ -250,10 +226,8 @@ class ExpressionBuilder
* *
* @param string $x Field in string format to be inspected by NOT LIKE() comparison. * @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 mixed $y Argument to be used in NOT LIKE() comparison.
*
* @return string
*/ */
public function notLike($x, $y/*, ?string $escapeChar = null */) public function notLike(string $x, $y/*, ?string $escapeChar = null */) : string
{ {
return $this->comparison($x, 'NOT LIKE', $y) . return $this->comparison($x, 'NOT LIKE', $y) .
(func_num_args() >= 3 ? sprintf(' ESCAPE %s', func_get_arg(2)) : ''); (func_num_args() >= 3 ? sprintf(' ESCAPE %s', func_get_arg(2)) : '');
...@@ -264,10 +238,8 @@ class ExpressionBuilder ...@@ -264,10 +238,8 @@ class ExpressionBuilder
* *
* @param string $x The field in string format to be inspected by IN() comparison. * @param string $x The field in string format to be inspected by IN() comparison.
* @param string|string[] $y The placeholder or the array of values to be used by IN() comparison. * @param string|string[] $y The placeholder or the array of values to be used by IN() comparison.
*
* @return string
*/ */
public function in($x, $y) public function in(string $x, $y) : string
{ {
return $this->comparison($x, 'IN', '(' . implode(', ', (array) $y) . ')'); return $this->comparison($x, 'IN', '(' . implode(', ', (array) $y) . ')');
} }
...@@ -277,10 +249,8 @@ class ExpressionBuilder ...@@ -277,10 +249,8 @@ class ExpressionBuilder
* *
* @param string $x The field in string format to be inspected by NOT IN() comparison. * @param string $x The field in string format to be inspected by NOT IN() comparison.
* @param string|string[] $y The placeholder or the array of values to be used by NOT IN() comparison. * @param string|string[] $y The placeholder or the array of values to be used by NOT IN() comparison.
*
* @return string
*/ */
public function notIn($x, $y) public function notIn(string $x, $y) : string
{ {
return $this->comparison($x, 'NOT IN', '(' . implode(', ', (array) $y) . ')'); return $this->comparison($x, 'NOT IN', '(' . implode(', ', (array) $y) . ')');
} }
...@@ -288,7 +258,7 @@ class ExpressionBuilder ...@@ -288,7 +258,7 @@ class ExpressionBuilder
/** /**
* Creates an SQL literal expression from the string. * Creates an SQL literal expression from the string.
*/ */
public function literal(string $input) public function literal(string $input) : string
{ {
return $this->connection->quote($input); return $this->connection->quote($input);
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment