| Conditions | 1 |
| Paths | 1 |
| Total Lines | 201 |
| Code Lines | 101 |
| 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 |
||
| 487 | public function queryProvider() |
||
| 488 | { |
||
| 489 | return [ |
||
| 490 | [ |
||
| 491 | '{ test (id: -5) { id } } ', |
||
| 492 | [ |
||
| 493 | 'queries' => [ |
||
| 494 | new Query('test', null, [ |
||
| 495 | new Argument('id', new Literal(-5)) |
||
| 496 | ], [ |
||
| 497 | new Field('id'), |
||
| 498 | ]) |
||
| 499 | ], |
||
| 500 | 'mutations' => [], |
||
| 501 | 'fragments' => [] |
||
| 502 | ] |
||
| 503 | ], |
||
| 504 | [ |
||
| 505 | "{ test (id: -5) \r\n { id } } ", |
||
| 506 | [ |
||
| 507 | 'queries' => [ |
||
| 508 | new Query('test', null, [ |
||
| 509 | new Argument('id', new Literal(-5)) |
||
| 510 | ], [ |
||
| 511 | new Field('id'), |
||
| 512 | ]) |
||
| 513 | ], |
||
| 514 | 'mutations' => [], |
||
| 515 | 'fragments' => [] |
||
| 516 | ] |
||
| 517 | ], |
||
| 518 | [ |
||
| 519 | 'query CheckTypeOfLuke { |
||
| 520 | hero(episode: EMPIRE) { |
||
| 521 | __typename, |
||
| 522 | name |
||
| 523 | } |
||
| 524 | }', |
||
| 525 | [ |
||
| 526 | 'queries' => [ |
||
| 527 | new Query('hero', null, [ |
||
| 528 | new Argument('episode', new Literal('EMPIRE')) |
||
| 529 | ], [ |
||
| 530 | new Field('__typename'), |
||
| 531 | new Field('name'), |
||
| 532 | ]) |
||
| 533 | ], |
||
| 534 | 'mutations' => [], |
||
| 535 | 'fragments' => [] |
||
| 536 | ] |
||
| 537 | ], |
||
| 538 | [ |
||
| 539 | '{ test { __typename, id } }', |
||
| 540 | [ |
||
| 541 | 'queries' => [ |
||
| 542 | new Query('test', null, [], [ |
||
| 543 | new Field('__typename'), |
||
| 544 | new Field('id'), |
||
| 545 | ]) |
||
| 546 | ], |
||
| 547 | 'mutations' => [], |
||
| 548 | 'fragments' => [] |
||
| 549 | ] |
||
| 550 | ], |
||
| 551 | [ |
||
| 552 | '{}', |
||
| 553 | [ |
||
| 554 | 'queries' => [], |
||
| 555 | 'mutations' => [], |
||
| 556 | 'fragments' => [] |
||
| 557 | ] |
||
| 558 | ], |
||
| 559 | [ |
||
| 560 | 'query test {}', |
||
| 561 | [ |
||
| 562 | 'queries' => [], |
||
| 563 | 'mutations' => [], |
||
| 564 | 'fragments' => [] |
||
| 565 | ] |
||
| 566 | ], |
||
| 567 | [ |
||
| 568 | 'query {}', |
||
| 569 | [ |
||
| 570 | 'queries' => [], |
||
| 571 | 'mutations' => [], |
||
| 572 | 'fragments' => [] |
||
| 573 | ] |
||
| 574 | ], |
||
| 575 | [ |
||
| 576 | 'mutation setName { setUserName }', |
||
| 577 | [ |
||
| 578 | 'queries' => [], |
||
| 579 | 'mutations' => [new Mutation('setUserName')], |
||
| 580 | 'fragments' => [] |
||
| 581 | ] |
||
| 582 | ], |
||
| 583 | [ |
||
| 584 | '{ test { ...userDataFragment } } fragment userDataFragment on User { id, name, email }', |
||
| 585 | [ |
||
| 586 | 'queries' => [ |
||
| 587 | new Query('test', null, [], [new FragmentReference('userDataFragment')]) |
||
| 588 | ], |
||
| 589 | 'mutations' => [], |
||
| 590 | 'fragments' => [ |
||
| 591 | new Fragment('userDataFragment', 'User', [ |
||
| 592 | new Field('id'), |
||
| 593 | new Field('name'), |
||
| 594 | new Field('email') |
||
| 595 | ]) |
||
| 596 | ] |
||
| 597 | ] |
||
| 598 | ], |
||
| 599 | [ |
||
| 600 | '{ user (id: 10, name: "max", float: 123.123 ) { id, name } }', |
||
| 601 | [ |
||
| 602 | 'queries' => [ |
||
| 603 | new Query( |
||
| 604 | 'user', |
||
| 605 | null, |
||
| 606 | [ |
||
| 607 | new Argument('id', new Literal('10')), |
||
| 608 | new Argument('name', new Literal('max')), |
||
| 609 | new Argument('float', new Literal('123.123')) |
||
| 610 | ], |
||
| 611 | [ |
||
| 612 | new Field('id'), |
||
| 613 | new Field('name') |
||
| 614 | ] |
||
| 615 | ) |
||
| 616 | ], |
||
| 617 | 'mutations' => [], |
||
| 618 | 'fragments' => [] |
||
| 619 | ] |
||
| 620 | ], |
||
| 621 | [ |
||
| 622 | '{ allUsers : users ( id: [ 1, 2, 3] ) { id } }', |
||
| 623 | [ |
||
| 624 | 'queries' => [ |
||
| 625 | new Query( |
||
| 626 | 'users', |
||
| 627 | 'allUsers', |
||
| 628 | [ |
||
| 629 | new Argument('id', new InputList([1, 2, 3])) |
||
| 630 | ], |
||
| 631 | [ |
||
| 632 | new Field('id') |
||
| 633 | ] |
||
| 634 | ) |
||
| 635 | ], |
||
| 636 | 'mutations' => [], |
||
| 637 | 'fragments' => [] |
||
| 638 | ] |
||
| 639 | ], |
||
| 640 | [ |
||
| 641 | '{ allUsers : users ( id: [ 1, "2", true, null] ) { id } }', |
||
| 642 | [ |
||
| 643 | 'queries' => [ |
||
| 644 | new Query( |
||
| 645 | 'users', |
||
| 646 | 'allUsers', |
||
| 647 | [ |
||
| 648 | new Argument('id', new InputList([1, "2", true, null])) |
||
| 649 | ], |
||
| 650 | [ |
||
| 651 | new Field('id') |
||
| 652 | ] |
||
| 653 | ) |
||
| 654 | ], |
||
| 655 | 'mutations' => [], |
||
| 656 | 'fragments' => [] |
||
| 657 | ] |
||
| 658 | ], |
||
| 659 | [ |
||
| 660 | '{ allUsers : users ( object: { "a": 123, "d": "asd", "b" : [ 1, 2, 4 ], "c": { "a" : 123, "b": "asd" } } ) { id } }', |
||
| 661 | [ |
||
| 662 | 'queries' => [ |
||
| 663 | new Query( |
||
| 664 | 'users', |
||
| 665 | 'allUsers', |
||
| 666 | [ |
||
| 667 | new Argument('object', new InputObject([ |
||
| 668 | 'a' => 123, |
||
| 669 | 'd' => 'asd', |
||
| 670 | 'b' => [1, 2, 4], |
||
| 671 | 'c' => [ |
||
| 672 | 'a' => 123, |
||
| 673 | 'b' => 'asd' |
||
| 674 | ] |
||
| 675 | ])) |
||
| 676 | ], |
||
| 677 | [ |
||
| 678 | new Field('id') |
||
| 679 | ] |
||
| 680 | ) |
||
| 681 | ], |
||
| 682 | 'mutations' => [], |
||
| 683 | 'fragments' => [] |
||
| 684 | ] |
||
| 685 | ] |
||
| 686 | ]; |
||
| 687 | } |
||
| 688 | |||
| 733 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.