Skip to content

Commit ab52d69

Browse files
committed
Merge pull request #3574 from jwage/query-types
Add proper types to Doctrine\DBAL\Query namespace.
2 parents 7d15260 + 8cf2d5c commit ab52d69

File tree

3 files changed

+97
-160
lines changed

3 files changed

+97
-160
lines changed

lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CompositeExpression implements Countable
4141
* @param string $type Instance type of composite expression.
4242
* @param self[]|string[] $parts Composition of expressions to be joined on composite expression.
4343
*/
44-
public function __construct($type, array $parts = [])
44+
public function __construct(string $type, array $parts = [])
4545
{
4646
$this->type = $type;
4747

@@ -51,11 +51,11 @@ public function __construct($type, array $parts = [])
5151
/**
5252
* Adds multiple parts to composite expression.
5353
*
54-
* @param self[]|string[] $parts
54+
* @param array<int, self|string> $parts
5555
*
56-
* @return \Doctrine\DBAL\Query\Expression\CompositeExpression
56+
* @return $this
5757
*/
58-
public function addMultiple(array $parts = [])
58+
public function addMultiple(array $parts = []) : self
5959
{
6060
foreach ($parts as $part) {
6161
$this->add($part);
@@ -67,11 +67,11 @@ public function addMultiple(array $parts = [])
6767
/**
6868
* Adds an expression to composite expression.
6969
*
70-
* @param mixed $part
70+
* @param self|string $part
7171
*
72-
* @return \Doctrine\DBAL\Query\Expression\CompositeExpression
72+
* @return $this
7373
*/
74-
public function add($part)
74+
public function add($part) : self
7575
{
7676
if (empty($part)) {
7777
return $this;
@@ -88,20 +88,16 @@ public function add($part)
8888

8989
/**
9090
* Retrieves the amount of expressions on composite expression.
91-
*
92-
* @return int
9391
*/
94-
public function count()
92+
public function count() : int
9593
{
9694
return count($this->parts);
9795
}
9896

9997
/**
10098
* Retrieves the string representation of this composite expression.
101-
*
102-
* @return string
10399
*/
104-
public function __toString()
100+
public function __toString() : string
105101
{
106102
if ($this->count() === 1) {
107103
return (string) $this->parts[0];
@@ -112,10 +108,8 @@ public function __toString()
112108

113109
/**
114110
* Returns the type of this composite expression (AND/OR).
115-
*
116-
* @return string
117111
*/
118-
public function getType()
112+
public function getType() : string
119113
{
120114
return $this->type;
121115
}

lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ public function __construct(Connection $connection)
5151
*
5252
* @param mixed $x Optional clause. Defaults = null, but requires
5353
* at least one defined when converting to string.
54-
*
55-
* @return CompositeExpression
5654
*/
57-
public function andX($x = null)
55+
public function andX($x = null) : CompositeExpression
5856
{
5957
return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
6058
}
@@ -70,10 +68,8 @@ public function andX($x = null)
7068
*
7169
* @param mixed $x Optional clause. Defaults = null, but requires
7270
* at least one defined when converting to string.
73-
*
74-
* @return CompositeExpression
7571
*/
76-
public function orX($x = null)
72+
public function orX($x = null) : CompositeExpression
7773
{
7874
return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
7975
}
@@ -84,10 +80,8 @@ public function orX($x = null)
8480
* @param mixed $x The left expression.
8581
* @param string $operator One of the ExpressionBuilder::* constants.
8682
* @param mixed $y The right expression.
87-
*
88-
* @return string
8983
*/
90-
public function comparison($x, $operator, $y)
84+
public function comparison($x, string $operator, $y) : string
9185
{
9286
return $x . ' ' . $operator . ' ' . $y;
9387
}
@@ -104,10 +98,8 @@ public function comparison($x, $operator, $y)
10498
*
10599
* @param mixed $x The left expression.
106100
* @param mixed $y The right expression.
107-
*
108-
* @return string
109101
*/
110-
public function eq($x, $y)
102+
public function eq($x, $y) : string
111103
{
112104
return $this->comparison($x, self::EQ, $y);
113105
}
@@ -123,10 +115,8 @@ public function eq($x, $y)
123115
*
124116
* @param mixed $x The left expression.
125117
* @param mixed $y The right expression.
126-
*
127-
* @return string
128118
*/
129-
public function neq($x, $y)
119+
public function neq($x, $y) : string
130120
{
131121
return $this->comparison($x, self::NEQ, $y);
132122
}
@@ -142,10 +132,8 @@ public function neq($x, $y)
142132
*
143133
* @param mixed $x The left expression.
144134
* @param mixed $y The right expression.
145-
*
146-
* @return string
147135
*/
148-
public function lt($x, $y)
136+
public function lt($x, $y) : string
149137
{
150138
return $this->comparison($x, self::LT, $y);
151139
}
@@ -161,10 +149,8 @@ public function lt($x, $y)
161149
*
162150
* @param mixed $x The left expression.
163151
* @param mixed $y The right expression.
164-
*
165-
* @return string
166152
*/
167-
public function lte($x, $y)
153+
public function lte($x, $y) : string
168154
{
169155
return $this->comparison($x, self::LTE, $y);
170156
}
@@ -180,10 +166,8 @@ public function lte($x, $y)
180166
*
181167
* @param mixed $x The left expression.
182168
* @param mixed $y The right expression.
183-
*
184-
* @return string
185169
*/
186-
public function gt($x, $y)
170+
public function gt($x, $y) : string
187171
{
188172
return $this->comparison($x, self::GT, $y);
189173
}
@@ -199,10 +183,8 @@ public function gt($x, $y)
199183
*
200184
* @param mixed $x The left expression.
201185
* @param mixed $y The right expression.
202-
*
203-
* @return string
204186
*/
205-
public function gte($x, $y)
187+
public function gte($x, $y) : string
206188
{
207189
return $this->comparison($x, self::GTE, $y);
208190
}
@@ -211,10 +193,8 @@ public function gte($x, $y)
211193
* Creates an IS NULL expression with the given arguments.
212194
*
213195
* @param string $x The field in string format to be restricted by IS NULL.
214-
*
215-
* @return string
216196
*/
217-
public function isNull($x)
197+
public function isNull(string $x) : string
218198
{
219199
return $x . ' IS NULL';
220200
}
@@ -223,10 +203,8 @@ public function isNull($x)
223203
* Creates an IS NOT NULL expression with the given arguments.
224204
*
225205
* @param string $x The field in string format to be restricted by IS NOT NULL.
226-
*
227-
* @return string
228206
*/
229-
public function isNotNull($x)
207+
public function isNotNull(string $x) : string
230208
{
231209
return $x . ' IS NOT NULL';
232210
}
@@ -236,10 +214,8 @@ public function isNotNull($x)
236214
*
237215
* @param string $x Field in string format to be inspected by LIKE() comparison.
238216
* @param mixed $y Argument to be used in LIKE() comparison.
239-
*
240-
* @return string
241217
*/
242-
public function like($x, $y/*, ?string $escapeChar = null */)
218+
public function like(string $x, $y/*, ?string $escapeChar = null */) : string
243219
{
244220
return $this->comparison($x, 'LIKE', $y) .
245221
(func_num_args() >= 3 ? sprintf(' ESCAPE %s', func_get_arg(2)) : '');
@@ -250,10 +226,8 @@ public function like($x, $y/*, ?string $escapeChar = null */)
250226
*
251227
* @param string $x Field in string format to be inspected by NOT LIKE() comparison.
252228
* @param mixed $y Argument to be used in NOT LIKE() comparison.
253-
*
254-
* @return string
255229
*/
256-
public function notLike($x, $y/*, ?string $escapeChar = null */)
230+
public function notLike(string $x, $y/*, ?string $escapeChar = null */) : string
257231
{
258232
return $this->comparison($x, 'NOT LIKE', $y) .
259233
(func_num_args() >= 3 ? sprintf(' ESCAPE %s', func_get_arg(2)) : '');
@@ -264,10 +238,8 @@ public function notLike($x, $y/*, ?string $escapeChar = null */)
264238
*
265239
* @param string $x The field in string format to be inspected by IN() comparison.
266240
* @param string|string[] $y The placeholder or the array of values to be used by IN() comparison.
267-
*
268-
* @return string
269241
*/
270-
public function in($x, $y)
242+
public function in(string $x, $y) : string
271243
{
272244
return $this->comparison($x, 'IN', '(' . implode(', ', (array) $y) . ')');
273245
}
@@ -277,18 +249,16 @@ public function in($x, $y)
277249
*
278250
* @param string $x The field in string format to be inspected by NOT IN() comparison.
279251
* @param string|string[] $y The placeholder or the array of values to be used by NOT IN() comparison.
280-
*
281-
* @return string
282252
*/
283-
public function notIn($x, $y)
253+
public function notIn(string $x, $y) : string
284254
{
285255
return $this->comparison($x, 'NOT IN', '(' . implode(', ', (array) $y) . ')');
286256
}
287257

288258
/**
289259
* Creates an SQL literal expression from the string.
290260
*/
291-
public function literal(string $input)
261+
public function literal(string $input) : string
292262
{
293263
return $this->connection->quote($input);
294264
}

0 commit comments

Comments
 (0)