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