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