| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 108 | 
| Code Lines | 76 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | ||
| 367 | public function upsert(ConnectionPDOInterface $db): array | ||
| 368 |     { | ||
| 369 | return [ | ||
| 370 | 'regular values' => [ | ||
| 371 | ['params' => ['T_upsert', ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3]]], | ||
| 372 | ['params' => ['T_upsert', ['email' => '[email protected]', 'address' => 'Universe', 'status' => 1]]], | ||
| 373 | ], | ||
| 374 | 'regular values with update part' => [ | ||
| 375 | ['params' => [ | ||
| 376 | 'T_upsert', | ||
| 377 | ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3], | ||
| 378 | ['address' => 'Moon', 'status' => 2], | ||
| 379 | ], | ||
| 380 | ], | ||
| 381 | [ | ||
| 382 | 'params' => [ | ||
| 383 | 'T_upsert', | ||
| 384 | ['email' => '[email protected]', 'address' => 'Universe', 'status' => 1], | ||
| 385 | ['address' => 'Moon', 'status' => 2], | ||
| 386 | ], | ||
| 387 | 'expected' => ['email' => '[email protected]', 'address' => 'Moon', 'status' => 2], | ||
| 388 | ], | ||
| 389 | ], | ||
| 390 | 'regular values without update part' => [ | ||
| 391 | ['params' => ['T_upsert', ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3], false]], | ||
| 392 | [ | ||
| 393 | 'params' => [ | ||
| 394 | 'T_upsert', | ||
| 395 | ['email' => '[email protected]', 'address' => 'Universe', 'status' => 1], | ||
| 396 | false, | ||
| 397 | ], | ||
| 398 | 'expected' => ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3], | ||
| 399 | ], | ||
| 400 | ], | ||
| 401 | 'query' => [ | ||
| 402 | [ | ||
| 403 | 'params' => [ | ||
| 404 | 'T_upsert', | ||
| 405 | (new query($db)) | ||
| 406 |                             ->select(['email', 'address', 'status' => new Expression('1')]) | ||
| 407 |                             ->from('customer') | ||
| 408 | ->where(['name' => 'user1']) | ||
| 409 | ->limit(1), | ||
| 410 | ], | ||
| 411 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], | ||
| 412 | ], | ||
| 413 | [ | ||
| 414 | 'params' => [ | ||
| 415 | 'T_upsert', | ||
| 416 | (new query($db)) | ||
| 417 |                             ->select(['email', 'address', 'status' => new Expression('2')]) | ||
| 418 |                             ->from('customer') | ||
| 419 | ->where(['name' => 'user1']) | ||
| 420 | ->limit(1), | ||
| 421 | ], | ||
| 422 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 2], | ||
| 423 | ], | ||
| 424 | ], | ||
| 425 | 'query with update part' => [ | ||
| 426 | [ | ||
| 427 | 'params' => [ | ||
| 428 | 'T_upsert', | ||
| 429 | (new query($db)) | ||
| 430 |                             ->select(['email', 'address', 'status' => new Expression('1')]) | ||
| 431 |                             ->from('customer') | ||
| 432 | ->where(['name' => 'user1']) | ||
| 433 | ->limit(1), | ||
| 434 | ['address' => 'Moon', 'status' => 2], | ||
| 435 | ], | ||
| 436 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], | ||
| 437 | ], | ||
| 438 | [ | ||
| 439 | 'params' => [ | ||
| 440 | 'T_upsert', | ||
| 441 | (new query($db)) | ||
| 442 |                             ->select(['email', 'address', 'status' => new Expression('3')]) | ||
| 443 |                             ->from('customer') | ||
| 444 | ->where(['name' => 'user1']) | ||
| 445 | ->limit(1), | ||
| 446 | ['address' => 'Moon', 'status' => 2], | ||
| 447 | ], | ||
| 448 | 'expected' => ['email' => '[email protected]', 'address' => 'Moon', 'status' => 2], | ||
| 449 | ], | ||
| 450 | ], | ||
| 451 | 'query without update part' => [ | ||
| 452 | [ | ||
| 453 | 'params' => [ | ||
| 454 | 'T_upsert', | ||
| 455 | (new query($db)) | ||
| 456 |                             ->select(['email', 'address', 'status' => new Expression('1')]) | ||
| 457 |                             ->from('customer') | ||
| 458 | ->where(['name' => 'user1']) | ||
| 459 | ->limit(1), | ||
| 460 | false, | ||
| 461 | ], | ||
| 462 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], | ||
| 463 | ], | ||
| 464 | [ | ||
| 465 | 'params' => [ | ||
| 466 | 'T_upsert', | ||
| 467 | (new query($db)) | ||
| 468 |                             ->select(['email', 'address', 'status' => new Expression('2')]) | ||
| 469 |                             ->from('customer') | ||
| 470 | ->where(['name' => 'user1']) | ||
| 471 | ->limit(1), | ||
| 472 | false, | ||
| 473 | ], | ||
| 474 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], | ||
| 475 | ], | ||
| 480 |