| 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 |
||
| 341 | public function upsert(ConnectionPDOInterface $db): array |
||
| 342 | { |
||
| 343 | return [ |
||
| 344 | 'regular values' => [ |
||
| 345 | ['params' => ['T_upsert', ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3]]], |
||
| 346 | ['params' => ['T_upsert', ['email' => '[email protected]', 'address' => 'Universe', 'status' => 1]]], |
||
| 347 | ], |
||
| 348 | 'regular values with update part' => [ |
||
| 349 | ['params' => [ |
||
| 350 | 'T_upsert', |
||
| 351 | ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3], |
||
| 352 | ['address' => 'Moon', 'status' => 2], |
||
| 353 | ], |
||
| 354 | ], |
||
| 355 | [ |
||
| 356 | 'params' => [ |
||
| 357 | 'T_upsert', |
||
| 358 | ['email' => '[email protected]', 'address' => 'Universe', 'status' => 1], |
||
| 359 | ['address' => 'Moon', 'status' => 2], |
||
| 360 | ], |
||
| 361 | 'expected' => ['email' => '[email protected]', 'address' => 'Moon', 'status' => 2], |
||
| 362 | ], |
||
| 363 | ], |
||
| 364 | 'regular values without update part' => [ |
||
| 365 | ['params' => ['T_upsert', ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3], false]], |
||
| 366 | [ |
||
| 367 | 'params' => [ |
||
| 368 | 'T_upsert', |
||
| 369 | ['email' => '[email protected]', 'address' => 'Universe', 'status' => 1], |
||
| 370 | false, |
||
| 371 | ], |
||
| 372 | 'expected' => ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3], |
||
| 373 | ], |
||
| 374 | ], |
||
| 375 | 'query' => [ |
||
| 376 | [ |
||
| 377 | 'params' => [ |
||
| 378 | 'T_upsert', |
||
| 379 | (new query($db)) |
||
| 380 | ->select(['email', 'address', 'status' => new Expression('1')]) |
||
| 381 | ->from('customer') |
||
| 382 | ->where(['name' => 'user1']) |
||
| 383 | ->limit(1), |
||
| 384 | ], |
||
| 385 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], |
||
| 386 | ], |
||
| 387 | [ |
||
| 388 | 'params' => [ |
||
| 389 | 'T_upsert', |
||
| 390 | (new query($db)) |
||
| 391 | ->select(['email', 'address', 'status' => new Expression('2')]) |
||
| 392 | ->from('customer') |
||
| 393 | ->where(['name' => 'user1']) |
||
| 394 | ->limit(1), |
||
| 395 | ], |
||
| 396 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 2], |
||
| 397 | ], |
||
| 398 | ], |
||
| 399 | 'query with update part' => [ |
||
| 400 | [ |
||
| 401 | 'params' => [ |
||
| 402 | 'T_upsert', |
||
| 403 | (new query($db)) |
||
| 404 | ->select(['email', 'address', 'status' => new Expression('1')]) |
||
| 405 | ->from('customer') |
||
| 406 | ->where(['name' => 'user1']) |
||
| 407 | ->limit(1), |
||
| 408 | ['address' => 'Moon', 'status' => 2], |
||
| 409 | ], |
||
| 410 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], |
||
| 411 | ], |
||
| 412 | [ |
||
| 413 | 'params' => [ |
||
| 414 | 'T_upsert', |
||
| 415 | (new query($db)) |
||
| 416 | ->select(['email', 'address', 'status' => new Expression('3')]) |
||
| 417 | ->from('customer') |
||
| 418 | ->where(['name' => 'user1']) |
||
| 419 | ->limit(1), |
||
| 420 | ['address' => 'Moon', 'status' => 2], |
||
| 421 | ], |
||
| 422 | 'expected' => ['email' => '[email protected]', 'address' => 'Moon', 'status' => 2], |
||
| 423 | ], |
||
| 424 | ], |
||
| 425 | 'query without 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 | false, |
||
| 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('2')]) |
||
| 443 | ->from('customer') |
||
| 444 | ->where(['name' => 'user1']) |
||
| 445 | ->limit(1), |
||
| 446 | false, |
||
| 447 | ], |
||
| 448 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], |
||
| 449 | ], |
||
| 454 |