| Conditions | 1 |
| Paths | 1 |
| Total Lines | 268 |
| 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 |
||
| 565 | new Location(1, 19) |
||
| 566 | ), |
||
| 567 | ], |
||
| 568 | 'fragments' => [], |
||
| 569 | 'fragmentReferences' => [], |
||
| 570 | 'variables' => [], |
||
| 571 | 'variableReferences' => [], |
||
| 572 | ], |
||
| 573 | ], |
||
| 574 | ]; |
||
| 575 | } |
||
| 576 | |||
| 577 | /** |
||
| 578 | * @dataProvider queryProvider |
||
| 579 | * |
||
| 580 | * @param mixed $query |
||
| 581 | * @param mixed $structure |
||
| 582 | */ |
||
| 583 | public function testParser($query, $structure): void |
||
| 584 | { |
||
| 585 | $parser = new Parser(); |
||
| 586 | $parsedStructure = $parser->parse($query); |
||
| 587 | |||
| 588 | $this->assertEquals($structure, $parsedStructure); |
||
| 589 | } |
||
| 590 | |||
| 591 | public function queryProvider() |
||
| 592 | { |
||
| 593 | return [ |
||
| 594 | [ |
||
| 595 | '{ film(id: 1 filmID: 2) { title } }', |
||
| 596 | [ |
||
| 597 | 'queries' => [ |
||
| 598 | new Query('film', null, [ |
||
| 599 | new Argument('id', new Literal(1, new Location(1, 12)), new Location(1, 8)), |
||
| 600 | new Argument('filmID', new Literal(2, new Location(1, 22)), new Location(1, 14)), |
||
| 601 | ], [ |
||
| 602 | new Field('title', null, [], [], new Location(1, 27)), |
||
| 603 | ], [], new Location(1, 3)), |
||
| 604 | ], |
||
| 605 | 'mutations' => [], |
||
| 606 | 'fragments' => [], |
||
| 607 | 'fragmentReferences' => [], |
||
| 608 | 'variables' => [], |
||
| 609 | 'variableReferences' => [], |
||
| 610 | ], |
||
| 611 | ], |
||
| 612 | [ |
||
| 613 | '{ test (id: -5) { id } } ', |
||
| 614 | [ |
||
| 615 | 'queries' => [ |
||
| 616 | new Query('test', null, [ |
||
| 617 | new Argument('id', new Literal(-5, new Location(1, 13)), new Location(1, 9)), |
||
| 618 | ], [ |
||
| 619 | new Field('id', null, [], [], new Location(1, 19)), |
||
| 620 | ], [], new Location(1, 3)), |
||
| 621 | ], |
||
| 622 | 'mutations' => [], |
||
| 623 | 'fragments' => [], |
||
| 624 | 'fragmentReferences' => [], |
||
| 625 | 'variables' => [], |
||
| 626 | 'variableReferences' => [], |
||
| 627 | ], |
||
| 628 | ], |
||
| 629 | [ |
||
| 630 | "{ test (id: -5) \r\n { id } } ", |
||
| 631 | [ |
||
| 632 | 'queries' => [ |
||
| 633 | new Query('test', null, [ |
||
| 634 | new Argument('id', new Literal(-5, new Location(1, 13)), new Location(1, 9)), |
||
| 635 | ], [ |
||
| 636 | new Field('id', null, [], [], new Location(2, 4)), |
||
| 637 | ], [], new Location(1, 3)), |
||
| 638 | ], |
||
| 639 | 'mutations' => [], |
||
| 640 | 'fragments' => [], |
||
| 641 | 'fragmentReferences' => [], |
||
| 642 | 'variables' => [], |
||
| 643 | 'variableReferences' => [], |
||
| 644 | ], |
||
| 645 | ], |
||
| 646 | [ |
||
| 647 | 'query CheckTypeOfLuke { |
||
| 648 | hero(episode: EMPIRE) { |
||
| 649 | __typename, |
||
| 650 | name |
||
| 651 | } |
||
| 652 | }', |
||
| 653 | [ |
||
| 654 | 'queries' => [ |
||
| 655 | new Query('hero', null, [ |
||
| 656 | new Argument('episode', new Literal('EMPIRE', new Location(2, 33)), new Location(2, 24)), |
||
| 657 | ], [ |
||
| 658 | new Field('__typename', null, [], [], new Location(3, 21)), |
||
| 659 | new Field('name', null, [], [], new Location(4, 21)), |
||
| 660 | ], [], new Location(2, 19)), |
||
| 661 | ], |
||
| 662 | 'mutations' => [], |
||
| 663 | 'fragments' => [], |
||
| 664 | 'fragmentReferences' => [], |
||
| 665 | 'variables' => [], |
||
| 666 | 'variableReferences' => [], |
||
| 667 | ], |
||
| 668 | ], |
||
| 669 | [ |
||
| 670 | '{ test { __typename, id } }', |
||
| 671 | [ |
||
| 672 | 'queries' => [ |
||
| 673 | new Query('test', null, [], [ |
||
| 674 | new Field('__typename', null, [], [], new Location(1, 10)), |
||
| 675 | new Field('id', null, [], [], new Location(1, 22)), |
||
| 676 | ], [], new Location(1, 3)), |
||
| 677 | ], |
||
| 678 | 'mutations' => [], |
||
| 679 | 'fragments' => [], |
||
| 680 | 'fragmentReferences' => [], |
||
| 681 | 'variables' => [], |
||
| 682 | 'variableReferences' => [], |
||
| 683 | ], |
||
| 684 | ], |
||
| 685 | [ |
||
| 686 | '{}', |
||
| 687 | [ |
||
| 688 | 'queries' => [], |
||
| 689 | 'mutations' => [], |
||
| 690 | 'fragments' => [], |
||
| 691 | 'fragmentReferences' => [], |
||
| 692 | 'variables' => [], |
||
| 693 | 'variableReferences' => [], |
||
| 694 | ], |
||
| 695 | ], |
||
| 696 | [ |
||
| 697 | 'query test {}', |
||
| 698 | [ |
||
| 699 | 'queries' => [], |
||
| 700 | 'mutations' => [], |
||
| 701 | 'fragments' => [], |
||
| 702 | 'fragmentReferences' => [], |
||
| 703 | 'variables' => [], |
||
| 704 | 'variableReferences' => [], |
||
| 705 | ], |
||
| 706 | ], |
||
| 707 | [ |
||
| 708 | 'query {}', |
||
| 709 | [ |
||
| 710 | 'queries' => [], |
||
| 711 | 'mutations' => [], |
||
| 712 | 'fragments' => [], |
||
| 713 | 'fragmentReferences' => [], |
||
| 714 | 'variables' => [], |
||
| 715 | 'variableReferences' => [], |
||
| 716 | ], |
||
| 717 | ], |
||
| 718 | [ |
||
| 719 | 'mutation setName { setUserName }', |
||
| 720 | [ |
||
| 721 | 'queries' => [], |
||
| 722 | 'mutations' => [new Mutation('setUserName', null, [], [], [], new Location(1, 20))], |
||
| 723 | 'fragments' => [], |
||
| 724 | 'fragmentReferences' => [], |
||
| 725 | 'variables' => [], |
||
| 726 | 'variableReferences' => [], |
||
| 727 | ], |
||
| 728 | ], |
||
| 729 | [ |
||
| 730 | '{ test { ...userDataFragment } } fragment userDataFragment on User { id, name, email }', |
||
| 731 | [ |
||
| 732 | 'queries' => [ |
||
| 733 | new Query('test', null, [], [new FragmentReference('userDataFragment', new Location(1, 13))], [], new Location(1, 3)), |
||
| 734 | ], |
||
| 735 | 'mutations' => [], |
||
| 736 | 'fragments' => [ |
||
| 737 | new Fragment('userDataFragment', 'User', [], [ |
||
| 738 | new Field('id', null, [], [], new Location(1, 70)), |
||
| 739 | new Field('name', null, [], [], new Location(1, 74)), |
||
| 740 | new Field('email', null, [], [], new Location(1, 80)), |
||
| 741 | ], new Location(1, 43)), |
||
| 742 | ], |
||
| 743 | 'fragmentReferences' => [ |
||
| 744 | new FragmentReference('userDataFragment', new Location(1, 13)), |
||
| 745 | ], |
||
| 746 | 'variables' => [], |
||
| 747 | 'variableReferences' => [], |
||
| 748 | ], |
||
| 749 | ], |
||
| 750 | [ |
||
| 751 | '{ user (id: 10, name: "max", float: 123.123 ) { id, name } }', |
||
| 752 | [ |
||
| 753 | 'queries' => [ |
||
| 754 | new Query( |
||
| 755 | 'user', |
||
| 756 | null, |
||
| 757 | [ |
||
| 758 | new Argument('id', new Literal('10', new Location(1, 13)), new Location(1, 9)), |
||
| 759 | new Argument('name', new Literal('max', new Location(1, 24)), new Location(1, 17)), |
||
| 760 | new Argument('float', new Literal('123.123', new Location(1, 37)), new Location(1, 30)), |
||
| 761 | ], |
||
| 762 | [ |
||
| 763 | new Field('id', null, [], [], new Location(1, 49)), |
||
| 764 | new Field('name', null, [], [], new Location(1, 53)), |
||
| 765 | ], |
||
| 766 | [], |
||
| 767 | new Location(1, 3) |
||
| 768 | ), |
||
| 769 | ], |
||
| 770 | 'mutations' => [], |
||
| 771 | 'fragments' => [], |
||
| 772 | 'fragmentReferences' => [], |
||
| 773 | 'variables' => [], |
||
| 774 | 'variableReferences' => [], |
||
| 775 | ], |
||
| 776 | ], |
||
| 777 | [ |
||
| 778 | '{ allUsers : users ( id: [ 1, 2, 3] ) { id } }', |
||
| 779 | [ |
||
| 780 | 'queries' => [ |
||
| 781 | new Query( |
||
| 782 | 'users', |
||
| 783 | 'allUsers', |
||
| 784 | [ |
||
| 785 | new Argument('id', new InputList([1, 2, 3], new Location(1, 26)), new Location(1, 22)), |
||
| 786 | ], |
||
| 787 | [ |
||
| 788 | new Field('id', null, [], [], new Location(1, 41)), |
||
| 789 | ], |
||
| 790 | [], |
||
| 791 | new Location(1, 14) |
||
| 792 | ), |
||
| 793 | ], |
||
| 794 | 'mutations' => [], |
||
| 795 | 'fragments' => [], |
||
| 796 | 'fragmentReferences' => [], |
||
| 797 | 'variables' => [], |
||
| 798 | 'variableReferences' => [], |
||
| 799 | ], |
||
| 800 | ], |
||
| 801 | [ |
||
| 802 | '{ allUsers : users ( id: [ 1, "2", true, null] ) { id } }', |
||
| 803 | [ |
||
| 804 | 'queries' => [ |
||
| 805 | new Query( |
||
| 806 | 'users', |
||
| 807 | 'allUsers', |
||
| 808 | [ |
||
| 809 | new Argument('id', new InputList([1, '2', true, null], new Location(1, 26)), new Location(1, 22)), |
||
| 810 | ], |
||
| 811 | [ |
||
| 812 | new Field('id', null, [], [], new Location(1, 52)), |
||
| 813 | ], |
||
| 814 | [], |
||
| 815 | new Location(1, 14) |
||
| 816 | ), |
||
| 817 | ], |
||
| 818 | 'mutations' => [], |
||
| 819 | 'fragments' => [], |
||
| 820 | 'fragmentReferences' => [], |
||
| 821 | 'variables' => [], |
||
| 822 | 'variableReferences' => [], |
||
| 823 | ], |
||
| 824 | ], |
||
| 825 | [ |
||
| 826 | '{ allUsers : users ( object: { "a": 123, "d": "asd", "b" : [ 1, 2, 4 ], "c": { "a" : 123, "b": "asd" } } ) { id } }', |
||
| 827 | [ |
||
| 828 | 'queries' => [ |
||
| 829 | new Query( |
||
| 830 | 'users', |
||
| 831 | 'allUsers', |
||
| 832 | [ |
||
| 833 | new Argument('object', new InputObject([ |
||
| 928 |