| Conditions | 1 |
| Paths | 1 |
| Total Lines | 264 |
| Code Lines | 164 |
| 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 |
||
| 518 | public function queryProvider() |
||
| 519 | { |
||
| 520 | return [ |
||
| 521 | [ |
||
| 522 | '{ film(id: 1 filmID: 2) { title } }', |
||
| 523 | [ |
||
| 524 | 'queries' => [ |
||
| 525 | new Query('film', null, [ |
||
| 526 | new Argument('id', new Literal(1, new Location(1, 12)), new Location(1, 8)), |
||
| 527 | new Argument('filmID', new Literal(2, new Location(1, 22)), new Location(1, 14)) |
||
| 528 | ], [ |
||
| 529 | new Field('title', null, [], new Location(1, 27)), |
||
| 530 | ], new Location(1, 3)) |
||
| 531 | ], |
||
| 532 | 'mutations' => [], |
||
| 533 | 'fragments' => [], |
||
| 534 | 'fragmentReferences' => [], |
||
| 535 | 'variables' => [], |
||
| 536 | 'variableReferences' => [] |
||
| 537 | ] |
||
| 538 | ], |
||
| 539 | [ |
||
| 540 | '{ test (id: -5) { id } } ', |
||
| 541 | [ |
||
| 542 | 'queries' => [ |
||
| 543 | new Query('test', null, [ |
||
| 544 | new Argument('id', new Literal(-5, new Location(1, 13)), new Location(1, 9)) |
||
| 545 | ], [ |
||
| 546 | new Field('id', null, [], new Location(1, 19)), |
||
| 547 | ], new Location(1, 3)) |
||
| 548 | ], |
||
| 549 | 'mutations' => [], |
||
| 550 | 'fragments' => [], |
||
| 551 | 'fragmentReferences' => [], |
||
| 552 | 'variables' => [], |
||
| 553 | 'variableReferences' => [] |
||
| 554 | ] |
||
| 555 | ], |
||
| 556 | [ |
||
| 557 | "{ test (id: -5) \r\n { id } } ", |
||
| 558 | [ |
||
| 559 | 'queries' => [ |
||
| 560 | new Query('test', null, [ |
||
| 561 | new Argument('id', new Literal(-5, new Location(1, 13)), new Location(1, 9)) |
||
| 562 | ], [ |
||
| 563 | new Field('id', null, [], new Location(2, 4)), |
||
| 564 | ], new Location(1, 3)) |
||
| 565 | ], |
||
| 566 | 'mutations' => [], |
||
| 567 | 'fragments' => [], |
||
| 568 | 'fragmentReferences' => [], |
||
| 569 | 'variables' => [], |
||
| 570 | 'variableReferences' => [] |
||
| 571 | ] |
||
| 572 | ], |
||
| 573 | [ |
||
| 574 | 'query CheckTypeOfLuke { |
||
| 575 | hero(episode: EMPIRE) { |
||
| 576 | __typename, |
||
| 577 | name |
||
| 578 | } |
||
| 579 | }', |
||
| 580 | [ |
||
| 581 | 'queries' => [ |
||
| 582 | new Query('hero', null, [ |
||
| 583 | new Argument('episode', new Literal('EMPIRE', new Location(2, 33)), new Location(2, 24)) |
||
| 584 | ], [ |
||
| 585 | new Field('__typename', null, [], new Location(3, 21)), |
||
| 586 | new Field('name', null, [], new Location(4, 21)), |
||
| 587 | ], new Location(2, 19)) |
||
| 588 | ], |
||
| 589 | 'mutations' => [], |
||
| 590 | 'fragments' => [], |
||
| 591 | 'fragmentReferences' => [], |
||
| 592 | 'variables' => [], |
||
| 593 | 'variableReferences' => [] |
||
| 594 | ] |
||
| 595 | ], |
||
| 596 | [ |
||
| 597 | '{ test { __typename, id } }', |
||
| 598 | [ |
||
| 599 | 'queries' => [ |
||
| 600 | new Query('test', null, [], [ |
||
| 601 | new Field('__typename', null, [], new Location(1, 10)), |
||
| 602 | new Field('id', null, [], new Location(1, 22)), |
||
| 603 | ], new Location(1, 3)) |
||
| 604 | ], |
||
| 605 | 'mutations' => [], |
||
| 606 | 'fragments' => [], |
||
| 607 | 'fragmentReferences' => [], |
||
| 608 | 'variables' => [], |
||
| 609 | 'variableReferences' => [] |
||
| 610 | ] |
||
| 611 | ], |
||
| 612 | [ |
||
| 613 | '{}', |
||
| 614 | [ |
||
| 615 | 'queries' => [], |
||
| 616 | 'mutations' => [], |
||
| 617 | 'fragments' => [], |
||
| 618 | 'fragmentReferences' => [], |
||
| 619 | 'variables' => [], |
||
| 620 | 'variableReferences' => [] |
||
| 621 | ] |
||
| 622 | ], |
||
| 623 | [ |
||
| 624 | 'query test {}', |
||
| 625 | [ |
||
| 626 | 'queries' => [], |
||
| 627 | 'mutations' => [], |
||
| 628 | 'fragments' => [], |
||
| 629 | 'fragmentReferences' => [], |
||
| 630 | 'variables' => [], |
||
| 631 | 'variableReferences' => [] |
||
| 632 | ] |
||
| 633 | ], |
||
| 634 | [ |
||
| 635 | 'query {}', |
||
| 636 | [ |
||
| 637 | 'queries' => [], |
||
| 638 | 'mutations' => [], |
||
| 639 | 'fragments' => [], |
||
| 640 | 'fragmentReferences' => [], |
||
| 641 | 'variables' => [], |
||
| 642 | 'variableReferences' => [] |
||
| 643 | ] |
||
| 644 | ], |
||
| 645 | [ |
||
| 646 | 'mutation setName { setUserName }', |
||
| 647 | [ |
||
| 648 | 'queries' => [], |
||
| 649 | 'mutations' => [new Mutation('setUserName', null, [], [], new Location(1, 20))], |
||
| 650 | 'fragments' => [], |
||
| 651 | 'fragmentReferences' => [], |
||
| 652 | 'variables' => [], |
||
| 653 | 'variableReferences' => [] |
||
| 654 | ] |
||
| 655 | ], |
||
| 656 | [ |
||
| 657 | '{ test { ...userDataFragment } } fragment userDataFragment on User { id, name, email }', |
||
| 658 | [ |
||
| 659 | 'queries' => [ |
||
| 660 | new Query('test', null, [], [new FragmentReference('userDataFragment', new Location(1, 13))], new Location(1, 3)) |
||
| 661 | ], |
||
| 662 | 'mutations' => [], |
||
| 663 | 'fragments' => [ |
||
| 664 | new Fragment('userDataFragment', 'User', [ |
||
| 665 | new Field('id', null, [], new Location(1, 70)), |
||
| 666 | new Field('name', null, [], new Location(1, 74)), |
||
| 667 | new Field('email', null, [], new Location(1, 80)) |
||
| 668 | ], new Location(1, 43)) |
||
| 669 | ], |
||
| 670 | 'fragmentReferences' => [ |
||
| 671 | new FragmentReference('userDataFragment', new Location(1, 13)) |
||
| 672 | ], |
||
| 673 | 'variables' => [], |
||
| 674 | 'variableReferences' => [] |
||
| 675 | ] |
||
| 676 | ], |
||
| 677 | [ |
||
| 678 | '{ user (id: 10, name: "max", float: 123.123 ) { id, name } }', |
||
| 679 | [ |
||
| 680 | 'queries' => [ |
||
| 681 | new Query( |
||
| 682 | 'user', |
||
| 683 | null, |
||
| 684 | [ |
||
| 685 | new Argument('id', new Literal('10', new Location(1, 13)), new Location(1, 9)), |
||
| 686 | new Argument('name', new Literal('max', new Location(1, 24)), new Location(1, 17)), |
||
| 687 | new Argument('float', new Literal('123.123', new Location(1, 37)), new Location(1, 30)) |
||
| 688 | ], |
||
| 689 | [ |
||
| 690 | new Field('id', null, [], new Location(1, 49)), |
||
| 691 | new Field('name', null, [], new Location(1, 53)) |
||
| 692 | ], |
||
| 693 | new Location(1, 3) |
||
| 694 | ) |
||
| 695 | ], |
||
| 696 | 'mutations' => [], |
||
| 697 | 'fragments' => [], |
||
| 698 | 'fragmentReferences' => [], |
||
| 699 | 'variables' => [], |
||
| 700 | 'variableReferences' => [] |
||
| 701 | ] |
||
| 702 | ], |
||
| 703 | [ |
||
| 704 | '{ allUsers : users ( id: [ 1, 2, 3] ) { id } }', |
||
| 705 | [ |
||
| 706 | 'queries' => [ |
||
| 707 | new Query( |
||
| 708 | 'users', |
||
| 709 | 'allUsers', |
||
| 710 | [ |
||
| 711 | new Argument('id', new InputList([1, 2, 3], new Location(1, 26)), new Location(1, 22)) |
||
| 712 | ], |
||
| 713 | [ |
||
| 714 | new Field('id', null, [], new Location(1, 41)) |
||
| 715 | ], |
||
| 716 | new Location(1, 14) |
||
| 717 | ) |
||
| 718 | ], |
||
| 719 | 'mutations' => [], |
||
| 720 | 'fragments' => [], |
||
| 721 | 'fragmentReferences' => [], |
||
| 722 | 'variables' => [], |
||
| 723 | 'variableReferences' => [] |
||
| 724 | ] |
||
| 725 | ], |
||
| 726 | [ |
||
| 727 | '{ allUsers : users ( id: [ 1, "2", true, null] ) { id } }', |
||
| 728 | [ |
||
| 729 | 'queries' => [ |
||
| 730 | new Query( |
||
| 731 | 'users', |
||
| 732 | 'allUsers', |
||
| 733 | [ |
||
| 734 | new Argument('id', new InputList([1, "2", true, null], new Location(1, 26)), new Location(1, 22)) |
||
| 735 | ], |
||
| 736 | [ |
||
| 737 | new Field('id', null, [], new Location(1, 52)) |
||
| 738 | ], |
||
| 739 | new Location(1, 14) |
||
| 740 | ) |
||
| 741 | ], |
||
| 742 | 'mutations' => [], |
||
| 743 | 'fragments' => [], |
||
| 744 | 'fragmentReferences' => [], |
||
| 745 | 'variables' => [], |
||
| 746 | 'variableReferences' => [] |
||
| 747 | ] |
||
| 748 | ], |
||
| 749 | [ |
||
| 750 | '{ allUsers : users ( object: { "a": 123, "d": "asd", "b" : [ 1, 2, 4 ], "c": { "a" : 123, "b": "asd" } } ) { id } }', |
||
| 751 | [ |
||
| 752 | 'queries' => [ |
||
| 753 | new Query( |
||
| 754 | 'users', |
||
| 755 | 'allUsers', |
||
| 756 | [ |
||
| 757 | new Argument('object', new InputObject([ |
||
| 758 | 'a' => 123, |
||
| 759 | 'd' => 'asd', |
||
| 760 | 'b' => [1, 2, 4], |
||
| 761 | 'c' => new InputObject([ |
||
| 762 | 'a' => 123, |
||
| 763 | 'b' => 'asd' |
||
| 764 | ], new Location(1, 79)) |
||
| 765 | ], new Location(1, 30)), new Location(1, 22)) |
||
| 766 | ], |
||
| 767 | [ |
||
| 768 | new Field('id', null, [], new Location(1, 112)) |
||
| 769 | ], |
||
| 770 | new Location(1, 14) |
||
| 771 | ) |
||
| 772 | ], |
||
| 773 | 'mutations' => [], |
||
| 774 | 'fragments' => [], |
||
| 775 | 'fragmentReferences' => [], |
||
| 776 | 'variables' => [], |
||
| 777 | 'variableReferences' => [] |
||
| 778 | ] |
||
| 779 | ] |
||
| 780 | ]; |
||
| 781 | } |
||
| 782 | |||
| 827 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.