Conditions | 1 |
Paths | 1 |
Total Lines | 309 |
Code Lines | 185 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
125 | public function dataExpandListParameters() |
||
126 | { |
||
127 | return [ |
||
128 | // Positional: Very simple with one needle |
||
129 | [ |
||
130 | 'SELECT * FROM Foo WHERE foo IN (?)', |
||
131 | [[1, 2, 3]], |
||
132 | [Connection::PARAM_INT_ARRAY], |
||
133 | 'SELECT * FROM Foo WHERE foo IN (?, ?, ?)', |
||
134 | [1, 2, 3], |
||
135 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], |
||
136 | ], |
||
137 | // Positional: One non-list before d one after list-needle |
||
138 | [ |
||
139 | 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?)', |
||
140 | ['string', [1, 2, 3]], |
||
141 | [ParameterType::STRING, Connection::PARAM_INT_ARRAY], |
||
142 | 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?)', |
||
143 | ['string', 1, 2, 3], |
||
144 | [ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], |
||
145 | ], |
||
146 | // Positional: One non-list after list-needle |
||
147 | [ |
||
148 | 'SELECT * FROM Foo WHERE bar IN (?) AND baz = ?', |
||
149 | [[1, 2, 3], 'foo'], |
||
150 | [Connection::PARAM_INT_ARRAY, ParameterType::STRING], |
||
151 | 'SELECT * FROM Foo WHERE bar IN (?, ?, ?) AND baz = ?', |
||
152 | [1, 2, 3, 'foo'], |
||
153 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], |
||
154 | ], |
||
155 | // Positional: One non-list before and one after list-needle |
||
156 | [ |
||
157 | 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ?', |
||
158 | [1, [1, 2, 3], 4], |
||
159 | [ParameterType::INTEGER, Connection::PARAM_INT_ARRAY, ParameterType::INTEGER], |
||
160 | 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ?', |
||
161 | [1, 1, 2, 3, 4], |
||
162 | [ |
||
163 | ParameterType::INTEGER, |
||
164 | ParameterType::INTEGER, |
||
165 | ParameterType::INTEGER, |
||
166 | ParameterType::INTEGER, |
||
167 | ParameterType::INTEGER, |
||
168 | ], |
||
169 | ], |
||
170 | // Positional: Two lists |
||
171 | [ |
||
172 | 'SELECT * FROM Foo WHERE foo IN (?, ?)', |
||
173 | [[1, 2, 3], [4, 5]], |
||
174 | [Connection::PARAM_INT_ARRAY, Connection::PARAM_INT_ARRAY], |
||
175 | 'SELECT * FROM Foo WHERE foo IN (?, ?, ?, ?, ?)', |
||
176 | [1, 2, 3, 4, 5], |
||
177 | [ |
||
178 | ParameterType::INTEGER, |
||
179 | ParameterType::INTEGER, |
||
180 | ParameterType::INTEGER, |
||
181 | ParameterType::INTEGER, |
||
182 | ParameterType::INTEGER, |
||
183 | ], |
||
184 | ], |
||
185 | // Positional: Empty "integer" array DDC-1978 |
||
186 | [ |
||
187 | 'SELECT * FROM Foo WHERE foo IN (?)', |
||
188 | [[]], |
||
189 | [Connection::PARAM_INT_ARRAY], |
||
190 | 'SELECT * FROM Foo WHERE foo IN (NULL)', |
||
191 | [], |
||
192 | [], |
||
193 | ], |
||
194 | // Positional: Empty "str" array DDC-1978 |
||
195 | [ |
||
196 | 'SELECT * FROM Foo WHERE foo IN (?)', |
||
197 | [[]], |
||
198 | [Connection::PARAM_STR_ARRAY], |
||
199 | 'SELECT * FROM Foo WHERE foo IN (NULL)', |
||
200 | [], |
||
201 | [], |
||
202 | ], |
||
203 | // Positional: explicit keys for params and types |
||
204 | [ |
||
205 | 'SELECT * FROM Foo WHERE foo = ? AND bar = ? AND baz = ?', |
||
206 | [1 => 'bar', 2 => 'baz', 0 => 1], |
||
207 | [2 => ParameterType::STRING, 1 => ParameterType::STRING], |
||
208 | 'SELECT * FROM Foo WHERE foo = ? AND bar = ? AND baz = ?', |
||
209 | [1 => 'bar', 0 => 1, 2 => 'baz'], |
||
210 | [1 => ParameterType::STRING, 2 => ParameterType::STRING], |
||
211 | ], |
||
212 | // Positional: explicit keys for array params and array types |
||
213 | [ |
||
214 | 'SELECT * FROM Foo WHERE foo IN (?) AND bar IN (?) AND baz = ?', |
||
215 | [1 => ['bar1', 'bar2'], 2 => true, 0 => [1, 2, 3]], |
||
216 | [2 => ParameterType::BOOLEAN, 1 => Connection::PARAM_STR_ARRAY, 0 => Connection::PARAM_INT_ARRAY], |
||
217 | 'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND bar IN (?, ?) AND baz = ?', |
||
218 | [1, 2, 3, 'bar1', 'bar2', true], |
||
219 | [ |
||
220 | ParameterType::INTEGER, |
||
221 | ParameterType::INTEGER, |
||
222 | ParameterType::INTEGER, |
||
223 | ParameterType::STRING, |
||
224 | ParameterType::STRING, |
||
225 | ParameterType::BOOLEAN, |
||
226 | ], |
||
227 | ], |
||
228 | // Positional starts from 1: One non-list before and one after list-needle |
||
229 | [ |
||
230 | 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ? AND foo IN (?)', |
||
231 | [1 => 1, 2 => [1, 2, 3], 3 => 4, 4 => [5, 6]], |
||
232 | [ |
||
233 | 1 => ParameterType::INTEGER, |
||
234 | 2 => Connection::PARAM_INT_ARRAY, |
||
235 | 3 => ParameterType::INTEGER, |
||
236 | 4 => Connection::PARAM_INT_ARRAY, |
||
237 | ], |
||
238 | 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ? AND foo IN (?, ?)', |
||
239 | [1, 1, 2, 3, 4, 5, 6], |
||
240 | [ |
||
241 | ParameterType::INTEGER, |
||
242 | ParameterType::INTEGER, |
||
243 | ParameterType::INTEGER, |
||
244 | ParameterType::INTEGER, |
||
245 | ParameterType::INTEGER, |
||
246 | ParameterType::INTEGER, |
||
247 | ParameterType::INTEGER, |
||
248 | ], |
||
249 | ], |
||
250 | // Named parameters : Very simple with param int |
||
251 | [ |
||
252 | 'SELECT * FROM Foo WHERE foo = :foo', |
||
253 | ['foo' => 1], |
||
254 | ['foo' => ParameterType::INTEGER], |
||
255 | 'SELECT * FROM Foo WHERE foo = ?', |
||
256 | [1], |
||
257 | [ParameterType::INTEGER], |
||
258 | ], |
||
259 | |||
260 | // Named parameters : Very simple with param int and string |
||
261 | [ |
||
262 | 'SELECT * FROM Foo WHERE foo = :foo AND bar = :bar', |
||
263 | ['bar' => 'Some String','foo' => 1], |
||
264 | ['foo' => ParameterType::INTEGER, 'bar' => ParameterType::STRING], |
||
265 | 'SELECT * FROM Foo WHERE foo = ? AND bar = ?', |
||
266 | [1,'Some String'], |
||
267 | [ParameterType::INTEGER, ParameterType::STRING], |
||
268 | ], |
||
269 | // Named parameters : Very simple with one needle |
||
270 | [ |
||
271 | 'SELECT * FROM Foo WHERE foo IN (:foo)', |
||
272 | ['foo' => [1, 2, 3]], |
||
273 | ['foo' => Connection::PARAM_INT_ARRAY], |
||
274 | 'SELECT * FROM Foo WHERE foo IN (?, ?, ?)', |
||
275 | [1, 2, 3], |
||
276 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], |
||
277 | ], |
||
278 | // Named parameters: One non-list before d one after list-needle |
||
279 | [ |
||
280 | 'SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar)', |
||
281 | ['foo' => 'string', 'bar' => [1, 2, 3]], |
||
282 | ['foo' => ParameterType::STRING, 'bar' => Connection::PARAM_INT_ARRAY], |
||
283 | 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?)', |
||
284 | ['string', 1, 2, 3], |
||
285 | [ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], |
||
286 | ], |
||
287 | // Named parameters: One non-list after list-needle |
||
288 | [ |
||
289 | 'SELECT * FROM Foo WHERE bar IN (:bar) AND baz = :baz', |
||
290 | ['bar' => [1, 2, 3], 'baz' => 'foo'], |
||
291 | ['bar' => Connection::PARAM_INT_ARRAY, 'baz' => ParameterType::STRING], |
||
292 | 'SELECT * FROM Foo WHERE bar IN (?, ?, ?) AND baz = ?', |
||
293 | [1, 2, 3, 'foo'], |
||
294 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], |
||
295 | ], |
||
296 | // Named parameters: One non-list before and one after list-needle |
||
297 | [ |
||
298 | 'SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar) AND baz = :baz', |
||
299 | ['bar' => [1, 2, 3],'foo' => 1, 'baz' => 4], |
||
300 | ['bar' => Connection::PARAM_INT_ARRAY, 'foo' => ParameterType::INTEGER, 'baz' => ParameterType::INTEGER], |
||
301 | 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ?', |
||
302 | [1, 1, 2, 3, 4], |
||
303 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], |
||
304 | ], |
||
305 | // Named parameters: Two lists |
||
306 | [ |
||
307 | 'SELECT * FROM Foo WHERE foo IN (:a, :b)', |
||
308 | ['b' => [4, 5],'a' => [1, 2, 3]], |
||
309 | ['a' => Connection::PARAM_INT_ARRAY, 'b' => Connection::PARAM_INT_ARRAY], |
||
310 | 'SELECT * FROM Foo WHERE foo IN (?, ?, ?, ?, ?)', |
||
311 | [1, 2, 3, 4, 5], |
||
312 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], |
||
313 | ], |
||
314 | // Named parameters : With the same name arg type string |
||
315 | [ |
||
316 | 'SELECT * FROM Foo WHERE foo <> :arg AND bar = :arg', |
||
317 | ['arg' => 'Some String'], |
||
318 | ['arg' => ParameterType::STRING], |
||
319 | 'SELECT * FROM Foo WHERE foo <> ? AND bar = ?', |
||
320 | ['Some String','Some String'], |
||
321 | [ParameterType::STRING,ParameterType::STRING], |
||
322 | ], |
||
323 | // Named parameters : With the same name arg |
||
324 | [ |
||
325 | 'SELECT * FROM Foo WHERE foo IN (:arg) AND NOT bar IN (:arg)', |
||
326 | ['arg' => [1, 2, 3]], |
||
327 | ['arg' => Connection::PARAM_INT_ARRAY], |
||
328 | 'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND NOT bar IN (?, ?, ?)', |
||
329 | [1, 2, 3, 1, 2, 3], |
||
330 | [ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER,ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER], |
||
331 | ], |
||
332 | |||
333 | // Named parameters : Same name, other name in between DBAL-299 |
||
334 | [ |
||
335 | 'SELECT * FROM Foo WHERE (:foo = 2) AND (:bar = 3) AND (:foo = 2)', |
||
336 | ['foo' => 2,'bar' => 3], |
||
337 | ['foo' => ParameterType::INTEGER,'bar' => ParameterType::INTEGER], |
||
338 | 'SELECT * FROM Foo WHERE (? = 2) AND (? = 3) AND (? = 2)', |
||
339 | [2, 3, 2], |
||
340 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], |
||
341 | ], |
||
342 | // Named parameters : Empty "integer" array DDC-1978 |
||
343 | [ |
||
344 | 'SELECT * FROM Foo WHERE foo IN (:foo)', |
||
345 | ['foo' => []], |
||
346 | ['foo' => Connection::PARAM_INT_ARRAY], |
||
347 | 'SELECT * FROM Foo WHERE foo IN (NULL)', |
||
348 | [], |
||
349 | [], |
||
350 | ], |
||
351 | // Named parameters : Two empty "str" array DDC-1978 |
||
352 | [ |
||
353 | 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar IN (:bar)', |
||
354 | ['foo' => [], 'bar' => []], |
||
355 | ['foo' => Connection::PARAM_STR_ARRAY, 'bar' => Connection::PARAM_STR_ARRAY], |
||
356 | 'SELECT * FROM Foo WHERE foo IN (NULL) OR bar IN (NULL)', |
||
357 | [], |
||
358 | [], |
||
359 | ], |
||
360 | [ |
||
361 | 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar OR baz = :baz', |
||
362 | ['foo' => [1, 2], 'bar' => 'bar', 'baz' => 'baz'], |
||
363 | ['foo' => Connection::PARAM_INT_ARRAY, 'baz' => 'string'], |
||
364 | 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ? OR baz = ?', |
||
365 | [1, 2, 'bar', 'baz'], |
||
366 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, 'string'], |
||
367 | ], |
||
368 | [ |
||
369 | 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', |
||
370 | ['foo' => [1, 2], 'bar' => 'bar'], |
||
371 | ['foo' => Connection::PARAM_INT_ARRAY], |
||
372 | 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', |
||
373 | [1, 2, 'bar'], |
||
374 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], |
||
375 | ], |
||
376 | // Params/types with colons |
||
377 | [ |
||
378 | 'SELECT * FROM Foo WHERE foo = :foo OR bar = :bar', |
||
379 | [':foo' => 'foo', ':bar' => 'bar'], |
||
380 | [':foo' => ParameterType::INTEGER], |
||
381 | 'SELECT * FROM Foo WHERE foo = ? OR bar = ?', |
||
382 | ['foo', 'bar'], |
||
383 | [ParameterType::INTEGER, ParameterType::STRING], |
||
384 | ], |
||
385 | [ |
||
386 | 'SELECT * FROM Foo WHERE foo = :foo OR bar = :bar', |
||
387 | [':foo' => 'foo', ':bar' => 'bar'], |
||
388 | [':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER], |
||
389 | 'SELECT * FROM Foo WHERE foo = ? OR bar = ?', |
||
390 | ['foo', 'bar'], |
||
391 | [ParameterType::INTEGER, ParameterType::INTEGER], |
||
392 | ], |
||
393 | [ |
||
394 | 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', |
||
395 | [':foo' => [1, 2], ':bar' => 'bar'], |
||
396 | ['foo' => Connection::PARAM_INT_ARRAY], |
||
397 | 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', |
||
398 | [1, 2, 'bar'], |
||
399 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], |
||
400 | ], |
||
401 | [ |
||
402 | 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', |
||
403 | ['foo' => [1, 2], 'bar' => 'bar'], |
||
404 | [':foo' => Connection::PARAM_INT_ARRAY], |
||
405 | 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', |
||
406 | [1, 2, 'bar'], |
||
407 | [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], |
||
408 | ], |
||
409 | // DBAL-522 - null valued parameters are not considered |
||
410 | [ |
||
411 | 'INSERT INTO Foo (foo, bar) values (:foo, :bar)', |
||
412 | ['foo' => 1, 'bar' => null], |
||
413 | [':foo' => ParameterType::INTEGER, ':bar' => ParameterType::NULL], |
||
414 | 'INSERT INTO Foo (foo, bar) values (?, ?)', |
||
415 | [1, null], |
||
416 | [ParameterType::INTEGER, ParameterType::NULL], |
||
417 | ], |
||
418 | [ |
||
419 | 'INSERT INTO Foo (foo, bar) values (?, ?)', |
||
420 | [1, null], |
||
421 | [ParameterType::INTEGER, ParameterType::NULL], |
||
422 | 'INSERT INTO Foo (foo, bar) values (?, ?)', |
||
423 | [1, null], |
||
424 | [ParameterType::INTEGER, ParameterType::NULL], |
||
425 | ], |
||
426 | // DBAL-1205 - Escaped single quotes SQL- and C-Style |
||
427 | [ |
||
428 | "SELECT * FROM Foo WHERE foo = :foo||''':not_a_param''\\'' OR bar = ''':not_a_param''\\'':bar", |
||
429 | [':foo' => 1, ':bar' => 2], |
||
430 | [':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER], |
||
431 | 'SELECT * FROM Foo WHERE foo = ?||\'\'\':not_a_param\'\'\\\'\' OR bar = \'\'\':not_a_param\'\'\\\'\'?', |
||
432 | [1, 2], |
||
433 | [ParameterType::INTEGER, ParameterType::INTEGER], |
||
434 | ], |
||
497 |