| Conditions | 1 |
| Paths | 1 |
| Total Lines | 291 |
| Code Lines | 186 |
| 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 |
||
| 242 | public function databaseUrls() |
||
| 243 | { |
||
| 244 | $driver = $this->createMock(Driver::class); |
||
| 245 | $driverClass = get_class($driver); |
||
| 246 | |||
| 247 | return [ |
||
| 248 | 'simple URL' => [ |
||
| 249 | 'mysql://foo:bar@localhost/baz', |
||
| 250 | [ |
||
| 251 | 'user' => 'foo', |
||
| 252 | 'password' => 'bar', |
||
| 253 | 'host' => 'localhost', |
||
| 254 | 'dbname' => 'baz', |
||
| 255 | 'driver' => PDOMySQLDriver::class, |
||
| 256 | ], |
||
| 257 | ], |
||
| 258 | 'simple URL with port' => [ |
||
| 259 | 'mysql://foo:bar@localhost:11211/baz', |
||
| 260 | [ |
||
| 261 | 'user' => 'foo', |
||
| 262 | 'password' => 'bar', |
||
| 263 | 'host' => 'localhost', |
||
| 264 | 'port' => 11211, |
||
| 265 | 'dbname' => 'baz', |
||
| 266 | 'driver' => PDOMySQLDriver::class, |
||
| 267 | ], |
||
| 268 | ], |
||
| 269 | 'sqlite relative URL with host' => [ |
||
| 270 | 'sqlite://localhost/foo/dbname.sqlite', |
||
| 271 | [ |
||
| 272 | 'path' => 'foo/dbname.sqlite', |
||
| 273 | 'driver' => PDOSqliteDriver::class, |
||
| 274 | ], |
||
| 275 | ], |
||
| 276 | 'sqlite absolute URL with host' => [ |
||
| 277 | 'sqlite://localhost//tmp/dbname.sqlite', |
||
| 278 | [ |
||
| 279 | 'path' => '/tmp/dbname.sqlite', |
||
| 280 | 'driver' => PDOSqliteDriver::class, |
||
| 281 | ], |
||
| 282 | ], |
||
| 283 | 'sqlite relative URL without host' => [ |
||
| 284 | 'sqlite:///foo/dbname.sqlite', |
||
| 285 | [ |
||
| 286 | 'path' => 'foo/dbname.sqlite', |
||
| 287 | 'driver' => PDOSqliteDriver::class, |
||
| 288 | ], |
||
| 289 | ], |
||
| 290 | 'sqlite absolute URL without host' => [ |
||
| 291 | 'sqlite:////tmp/dbname.sqlite', |
||
| 292 | [ |
||
| 293 | 'path' => '/tmp/dbname.sqlite', |
||
| 294 | 'driver' => PDOSqliteDriver::class, |
||
| 295 | ], |
||
| 296 | ], |
||
| 297 | 'sqlite memory' => [ |
||
| 298 | 'sqlite:///:memory:', |
||
| 299 | [ |
||
| 300 | 'memory' => true, |
||
| 301 | 'driver' => PDOSqliteDriver::class, |
||
| 302 | ], |
||
| 303 | ], |
||
| 304 | 'sqlite memory with host' => [ |
||
| 305 | 'sqlite://localhost/:memory:', |
||
| 306 | [ |
||
| 307 | 'memory' => true, |
||
| 308 | 'driver' => PDOSqliteDriver::class, |
||
| 309 | ], |
||
| 310 | ], |
||
| 311 | 'params parsed from URL override individual params' => [ |
||
| 312 | [ |
||
| 313 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
| 314 | 'password' => 'lulz', |
||
| 315 | ], |
||
| 316 | [ |
||
| 317 | 'user' => 'foo', |
||
| 318 | 'password' => 'bar', |
||
| 319 | 'host' => 'localhost', |
||
| 320 | 'dbname' => 'baz', |
||
| 321 | 'driver' => PDOMySQLDriver::class, |
||
| 322 | ], |
||
| 323 | ], |
||
| 324 | 'params not parsed from URL but individual params are preserved' => [ |
||
| 325 | [ |
||
| 326 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
| 327 | 'port' => 1234, |
||
| 328 | ], |
||
| 329 | [ |
||
| 330 | 'user' => 'foo', |
||
| 331 | 'password' => 'bar', |
||
| 332 | 'host' => 'localhost', |
||
| 333 | 'port' => 1234, |
||
| 334 | 'dbname' => 'baz', |
||
| 335 | 'driver' => PDOMySQLDriver::class, |
||
| 336 | ], |
||
| 337 | ], |
||
| 338 | 'query params from URL are used as extra params' => [ |
||
| 339 | 'url' => 'mysql://foo:bar@localhost/dbname?charset=UTF-8', |
||
| 340 | ['charset' => 'UTF-8'], |
||
| 341 | ], |
||
| 342 | 'simple URL with fallthrough scheme not defined in map' => [ |
||
| 343 | 'sqlsrv://foo:bar@localhost/baz', |
||
| 344 | [ |
||
| 345 | 'user' => 'foo', |
||
| 346 | 'password' => 'bar', |
||
| 347 | 'host' => 'localhost', |
||
| 348 | 'dbname' => 'baz', |
||
| 349 | 'driver' => SQLSrvDriver::class, |
||
| 350 | ], |
||
| 351 | ], |
||
| 352 | 'simple URL with fallthrough scheme containing underscores fails' => [ |
||
| 353 | 'pdo_mysql://foo:bar@localhost/baz', |
||
| 354 | false, |
||
| 355 | ], |
||
| 356 | 'simple URL with fallthrough scheme containing dashes works' => [ |
||
| 357 | 'pdo-mysql://foo:bar@localhost/baz', |
||
| 358 | [ |
||
| 359 | 'user' => 'foo', |
||
| 360 | 'password' => 'bar', |
||
| 361 | 'host' => 'localhost', |
||
| 362 | 'dbname' => 'baz', |
||
| 363 | 'driver' => PDOMySQLDriver::class, |
||
| 364 | ], |
||
| 365 | ], |
||
| 366 | 'simple URL with percent encoding' => [ |
||
| 367 | 'mysql://foo%3A:bar%2F@localhost/baz+baz%40', |
||
| 368 | [ |
||
| 369 | 'user' => 'foo:', |
||
| 370 | 'password' => 'bar/', |
||
| 371 | 'host' => 'localhost', |
||
| 372 | 'dbname' => 'baz+baz@', |
||
| 373 | 'driver' => PDOMySQLDriver::class, |
||
| 374 | ], |
||
| 375 | ], |
||
| 376 | 'simple URL with percent sign in password' => [ |
||
| 377 | 'mysql://foo:bar%25bar@localhost/baz', |
||
| 378 | [ |
||
| 379 | 'user' => 'foo', |
||
| 380 | 'password' => 'bar%bar', |
||
| 381 | 'host' => 'localhost', |
||
| 382 | 'dbname' => 'baz', |
||
| 383 | 'driver' => PDOMySQLDriver::class, |
||
| 384 | ], |
||
| 385 | ], |
||
| 386 | |||
| 387 | // DBAL-1234 |
||
| 388 | 'URL without scheme and without any driver information' => [ |
||
| 389 | ['url' => '//foo:bar@localhost/baz'], |
||
| 390 | false, |
||
| 391 | ], |
||
| 392 | 'URL without scheme but default PDO driver' => [ |
||
| 393 | [ |
||
| 394 | 'url' => '//foo:bar@localhost/baz', |
||
| 395 | 'pdo' => true, |
||
| 396 | ], |
||
| 397 | false, |
||
| 398 | ], |
||
| 399 | 'URL without scheme but default driver' => [ |
||
| 400 | [ |
||
| 401 | 'url' => '//foo:bar@localhost/baz', |
||
| 402 | 'driver' => 'pdo_mysql', |
||
| 403 | ], |
||
| 404 | [ |
||
| 405 | 'user' => 'foo', |
||
| 406 | 'password' => 'bar', |
||
| 407 | 'host' => 'localhost', |
||
| 408 | 'dbname' => 'baz', |
||
| 409 | 'driver' => PDOMySQLDriver::class, |
||
| 410 | ], |
||
| 411 | ], |
||
| 412 | 'URL without scheme but custom driver' => [ |
||
| 413 | [ |
||
| 414 | 'url' => '//foo:bar@localhost/baz', |
||
| 415 | 'driverClass' => $driverClass, |
||
| 416 | ], |
||
| 417 | [ |
||
| 418 | 'user' => 'foo', |
||
| 419 | 'password' => 'bar', |
||
| 420 | 'host' => 'localhost', |
||
| 421 | 'dbname' => 'baz', |
||
| 422 | 'driverClass' => $driverClass, |
||
| 423 | ], |
||
| 424 | ], |
||
| 425 | 'URL without scheme but default PDO driver and default driver' => [ |
||
| 426 | [ |
||
| 427 | 'url' => '//foo:bar@localhost/baz', |
||
| 428 | 'pdo' => true, |
||
| 429 | 'driver' => 'pdo_mysql', |
||
| 430 | ], |
||
| 431 | [ |
||
| 432 | 'user' => 'foo', |
||
| 433 | 'password' => 'bar', |
||
| 434 | 'host' => 'localhost', |
||
| 435 | 'dbname' => 'baz', |
||
| 436 | 'driver' => PDOMySQLDriver::class, |
||
| 437 | ], |
||
| 438 | ], |
||
| 439 | 'URL without scheme but driver and custom driver' => [ |
||
| 440 | [ |
||
| 441 | 'url' => '//foo:bar@localhost/baz', |
||
| 442 | 'driver' => 'pdo_mysql', |
||
| 443 | 'driverClass' => $driverClass, |
||
| 444 | ], |
||
| 445 | [ |
||
| 446 | 'user' => 'foo', |
||
| 447 | 'password' => 'bar', |
||
| 448 | 'host' => 'localhost', |
||
| 449 | 'dbname' => 'baz', |
||
| 450 | 'driverClass' => $driverClass, |
||
| 451 | ], |
||
| 452 | ], |
||
| 453 | 'URL with default PDO driver' => [ |
||
| 454 | [ |
||
| 455 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
| 456 | 'pdo' => true, |
||
| 457 | ], |
||
| 458 | [ |
||
| 459 | 'user' => 'foo', |
||
| 460 | 'password' => 'bar', |
||
| 461 | 'host' => 'localhost', |
||
| 462 | 'dbname' => 'baz', |
||
| 463 | 'driver' => PDOMySQLDriver::class, |
||
| 464 | ], |
||
| 465 | ], |
||
| 466 | 'URL with default driver' => [ |
||
| 467 | [ |
||
| 468 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
| 469 | 'driver' => 'sqlite', |
||
| 470 | ], |
||
| 471 | [ |
||
| 472 | 'user' => 'foo', |
||
| 473 | 'password' => 'bar', |
||
| 474 | 'host' => 'localhost', |
||
| 475 | 'dbname' => 'baz', |
||
| 476 | 'driver' => PDOMySQLDriver::class, |
||
| 477 | ], |
||
| 478 | ], |
||
| 479 | 'URL with default custom driver' => [ |
||
| 480 | [ |
||
| 481 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
| 482 | 'driverClass' => $driverClass, |
||
| 483 | ], |
||
| 484 | [ |
||
| 485 | 'user' => 'foo', |
||
| 486 | 'password' => 'bar', |
||
| 487 | 'host' => 'localhost', |
||
| 488 | 'dbname' => 'baz', |
||
| 489 | 'driver' => PDOMySQLDriver::class, |
||
| 490 | ], |
||
| 491 | ], |
||
| 492 | 'URL with default PDO driver and default driver' => [ |
||
| 493 | [ |
||
| 494 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
| 495 | 'pdo' => true, |
||
| 496 | 'driver' => 'sqlite', |
||
| 497 | ], |
||
| 498 | [ |
||
| 499 | 'user' => 'foo', |
||
| 500 | 'password' => 'bar', |
||
| 501 | 'host' => 'localhost', |
||
| 502 | 'dbname' => 'baz', |
||
| 503 | 'driver' => PDOMySQLDriver::class, |
||
| 504 | ], |
||
| 505 | ], |
||
| 506 | 'URL with default driver and default custom driver' => [ |
||
| 507 | [ |
||
| 508 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
| 509 | 'driver' => 'sqlite', |
||
| 510 | 'driverClass' => $driverClass, |
||
| 511 | ], |
||
| 512 | [ |
||
| 513 | 'user' => 'foo', |
||
| 514 | 'password' => 'bar', |
||
| 515 | 'host' => 'localhost', |
||
| 516 | 'dbname' => 'baz', |
||
| 517 | 'driver' => PDOMySQLDriver::class, |
||
| 518 | ], |
||
| 519 | ], |
||
| 520 | 'URL with default PDO driver and default driver and default custom driver' => [ |
||
| 521 | [ |
||
| 522 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
| 523 | 'pdo' => true, |
||
| 524 | 'driver' => 'sqlite', |
||
| 525 | 'driverClass' => $driverClass, |
||
| 526 | ], |
||
| 527 | [ |
||
| 528 | 'user' => 'foo', |
||
| 529 | 'password' => 'bar', |
||
| 530 | 'host' => 'localhost', |
||
| 531 | 'dbname' => 'baz', |
||
| 532 | 'driver' => PDOMySQLDriver::class, |
||
| 533 | ], |
||
| 538 |