Conditions | 1 |
Paths | 1 |
Total Lines | 228 |
Code Lines | 146 |
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 |
||
200 | public function databaseUrls() : iterable |
||
201 | { |
||
202 | $driver = $this->createMock(Driver::class); |
||
203 | $driverClass = get_class($driver); |
||
204 | |||
205 | return [ |
||
206 | 'simple URL' => [ |
||
207 | 'mysql://foo:bar@localhost/baz', |
||
208 | [ |
||
209 | 'user' => 'foo', |
||
210 | 'password' => 'bar', |
||
211 | 'host' => 'localhost', |
||
212 | 'dbname' => 'baz', |
||
213 | 'driver' => PDOMySQLDriver::class, |
||
214 | ], |
||
215 | ], |
||
216 | 'simple URL with port' => [ |
||
217 | 'mysql://foo:bar@localhost:11211/baz', |
||
218 | [ |
||
219 | 'user' => 'foo', |
||
220 | 'password' => 'bar', |
||
221 | 'host' => 'localhost', |
||
222 | 'port' => 11211, |
||
223 | 'dbname' => 'baz', |
||
224 | 'driver' => PDOMySQLDriver::class, |
||
225 | ], |
||
226 | ], |
||
227 | 'sqlite relative URL with host' => [ |
||
228 | 'sqlite://localhost/foo/dbname.sqlite', |
||
229 | [ |
||
230 | 'path' => 'foo/dbname.sqlite', |
||
231 | 'driver' => PDOSqliteDriver::class, |
||
232 | ], |
||
233 | ], |
||
234 | 'sqlite absolute URL with host' => [ |
||
235 | 'sqlite://localhost//tmp/dbname.sqlite', |
||
236 | [ |
||
237 | 'path' => '/tmp/dbname.sqlite', |
||
238 | 'driver' => PDOSqliteDriver::class, |
||
239 | ], |
||
240 | ], |
||
241 | 'sqlite relative URL without host' => [ |
||
242 | 'sqlite:///foo/dbname.sqlite', |
||
243 | [ |
||
244 | 'path' => 'foo/dbname.sqlite', |
||
245 | 'driver' => PDOSqliteDriver::class, |
||
246 | ], |
||
247 | ], |
||
248 | 'sqlite absolute URL without host' => [ |
||
249 | 'sqlite:////tmp/dbname.sqlite', |
||
250 | [ |
||
251 | 'path' => '/tmp/dbname.sqlite', |
||
252 | 'driver' => PDOSqliteDriver::class, |
||
253 | ], |
||
254 | ], |
||
255 | 'sqlite memory' => [ |
||
256 | 'sqlite:///:memory:', |
||
257 | [ |
||
258 | 'memory' => true, |
||
259 | 'driver' => PDOSqliteDriver::class, |
||
260 | ], |
||
261 | ], |
||
262 | 'sqlite memory with host' => [ |
||
263 | 'sqlite://localhost/:memory:', |
||
264 | [ |
||
265 | 'memory' => true, |
||
266 | 'driver' => PDOSqliteDriver::class, |
||
267 | ], |
||
268 | ], |
||
269 | 'params parsed from URL override individual params' => [ |
||
270 | [ |
||
271 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
272 | 'password' => 'lulz', |
||
273 | ], |
||
274 | [ |
||
275 | 'user' => 'foo', |
||
276 | 'password' => 'bar', |
||
277 | 'host' => 'localhost', |
||
278 | 'dbname' => 'baz', |
||
279 | 'driver' => PDOMySQLDriver::class, |
||
280 | ], |
||
281 | ], |
||
282 | 'params not parsed from URL but individual params are preserved' => [ |
||
283 | [ |
||
284 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
285 | 'port' => 1234, |
||
286 | ], |
||
287 | [ |
||
288 | 'user' => 'foo', |
||
289 | 'password' => 'bar', |
||
290 | 'host' => 'localhost', |
||
291 | 'port' => 1234, |
||
292 | 'dbname' => 'baz', |
||
293 | 'driver' => PDOMySQLDriver::class, |
||
294 | ], |
||
295 | ], |
||
296 | 'query params from URL are used as extra params' => [ |
||
297 | 'url' => 'mysql://foo:bar@localhost/dbname?charset=UTF-8', |
||
298 | ['charset' => 'UTF-8'], |
||
299 | ], |
||
300 | 'simple URL with fallthrough scheme not defined in map' => [ |
||
301 | 'sqlsrv://foo:bar@localhost/baz', |
||
302 | [ |
||
303 | 'user' => 'foo', |
||
304 | 'password' => 'bar', |
||
305 | 'host' => 'localhost', |
||
306 | 'dbname' => 'baz', |
||
307 | 'driver' => SQLSrvDriver::class, |
||
308 | ], |
||
309 | ], |
||
310 | 'simple URL with fallthrough scheme containing underscores fails' => [ |
||
311 | 'drizzle_pdo_mysql://foo:bar@localhost/baz', |
||
312 | false, |
||
313 | ], |
||
314 | 'simple URL with fallthrough scheme containing dashes works' => [ |
||
315 | 'drizzle-pdo-mysql://foo:bar@localhost/baz', |
||
316 | [ |
||
317 | 'user' => 'foo', |
||
318 | 'password' => 'bar', |
||
319 | 'host' => 'localhost', |
||
320 | 'dbname' => 'baz', |
||
321 | 'driver' => DrizzlePDOMySqlDriver::class, |
||
322 | ], |
||
323 | ], |
||
324 | 'simple URL with percent encoding' => [ |
||
325 | 'mysql://foo%3A:bar%2F@localhost/baz+baz%40', |
||
326 | [ |
||
327 | 'user' => 'foo:', |
||
328 | 'password' => 'bar/', |
||
329 | 'host' => 'localhost', |
||
330 | 'dbname' => 'baz+baz@', |
||
331 | 'driver' => PDOMySQLDriver::class, |
||
332 | ], |
||
333 | ], |
||
334 | 'simple URL with percent sign in password' => [ |
||
335 | 'mysql://foo:bar%25bar@localhost/baz', |
||
336 | [ |
||
337 | 'user' => 'foo', |
||
338 | 'password' => 'bar%bar', |
||
339 | 'host' => 'localhost', |
||
340 | 'dbname' => 'baz', |
||
341 | 'driver' => PDOMySQLDriver::class, |
||
342 | ], |
||
343 | ], |
||
344 | |||
345 | // DBAL-1234 |
||
346 | 'URL without scheme and without any driver information' => [ |
||
347 | ['url' => '//foo:bar@localhost/baz'], |
||
348 | false, |
||
349 | ], |
||
350 | 'URL without scheme but default driver' => [ |
||
351 | [ |
||
352 | 'url' => '//foo:bar@localhost/baz', |
||
353 | 'driver' => 'pdo_mysql', |
||
354 | ], |
||
355 | [ |
||
356 | 'user' => 'foo', |
||
357 | 'password' => 'bar', |
||
358 | 'host' => 'localhost', |
||
359 | 'dbname' => 'baz', |
||
360 | 'driver' => PDOMySQLDriver::class, |
||
361 | ], |
||
362 | ], |
||
363 | 'URL without scheme but custom driver' => [ |
||
364 | [ |
||
365 | 'url' => '//foo:bar@localhost/baz', |
||
366 | 'driverClass' => $driverClass, |
||
367 | ], |
||
368 | [ |
||
369 | 'user' => 'foo', |
||
370 | 'password' => 'bar', |
||
371 | 'host' => 'localhost', |
||
372 | 'dbname' => 'baz', |
||
373 | 'driverClass' => $driverClass, |
||
374 | ], |
||
375 | ], |
||
376 | 'URL without scheme but driver and custom driver' => [ |
||
377 | [ |
||
378 | 'url' => '//foo:bar@localhost/baz', |
||
379 | 'driver' => 'pdo_mysql', |
||
380 | 'driverClass' => $driverClass, |
||
381 | ], |
||
382 | [ |
||
383 | 'user' => 'foo', |
||
384 | 'password' => 'bar', |
||
385 | 'host' => 'localhost', |
||
386 | 'dbname' => 'baz', |
||
387 | 'driverClass' => $driverClass, |
||
388 | ], |
||
389 | ], |
||
390 | 'URL with default driver' => [ |
||
391 | [ |
||
392 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
393 | 'driver' => 'sqlite', |
||
394 | ], |
||
395 | [ |
||
396 | 'user' => 'foo', |
||
397 | 'password' => 'bar', |
||
398 | 'host' => 'localhost', |
||
399 | 'dbname' => 'baz', |
||
400 | 'driver' => PDOMySQLDriver::class, |
||
401 | ], |
||
402 | ], |
||
403 | 'URL with default custom driver' => [ |
||
404 | [ |
||
405 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
406 | 'driverClass' => $driverClass, |
||
407 | ], |
||
408 | [ |
||
409 | 'user' => 'foo', |
||
410 | 'password' => 'bar', |
||
411 | 'host' => 'localhost', |
||
412 | 'dbname' => 'baz', |
||
413 | 'driver' => PDOMySQLDriver::class, |
||
414 | ], |
||
415 | ], |
||
416 | 'URL with default driver and default custom driver' => [ |
||
417 | [ |
||
418 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
419 | 'driver' => 'sqlite', |
||
420 | 'driverClass' => $driverClass, |
||
421 | ], |
||
422 | [ |
||
423 | 'user' => 'foo', |
||
424 | 'password' => 'bar', |
||
425 | 'host' => 'localhost', |
||
426 | 'dbname' => 'baz', |
||
427 | 'driver' => PDOMySQLDriver::class, |
||
428 | ], |
||
433 |