Conditions | 1 |
Paths | 1 |
Total Lines | 84 |
Code Lines | 45 |
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 |
||
16 | public function testInternalVariableArgument() |
||
17 | { |
||
18 | $schema = new Schema([ |
||
19 | 'query' => new ObjectType([ |
||
20 | 'name' => 'RootQuery', |
||
21 | 'fields' => [ |
||
22 | 'user' => [ |
||
23 | 'type' => new ObjectType([ |
||
24 | 'name' => 'User', |
||
25 | 'fields' => [ |
||
26 | 'id' => new IdType(), |
||
27 | 'name' => new StringType(), |
||
28 | 'age' => new IntType(), |
||
29 | 'friends' => new ListType(new ObjectType([ |
||
30 | 'name' => 'UserFriend', |
||
31 | 'fields' => [ |
||
32 | 'id' => new IdType(), |
||
33 | 'name' => new StringType(), |
||
34 | 'age' => new IntType(), |
||
35 | ], |
||
36 | ])), |
||
37 | ], |
||
38 | ]), |
||
39 | 'resolve' => function () { |
||
40 | return [ |
||
41 | 'id' => 1, |
||
42 | 'name' => 'John', |
||
43 | 'age' => 30, |
||
44 | 'friends' => [ |
||
45 | [ |
||
46 | 'id' => 2, |
||
47 | 'name' => 'Friend 1', |
||
48 | 'age' => 31, |
||
49 | ], |
||
50 | [ |
||
51 | 'id' => 3, |
||
52 | 'name' => 'Friend 2', |
||
53 | 'age' => 32, |
||
54 | ], |
||
55 | ], |
||
56 | ]; |
||
57 | }, |
||
58 | ], |
||
59 | ], |
||
60 | ]), |
||
61 | ]); |
||
62 | $processor = new Processor($schema); |
||
63 | $response = $processor->processPayload(' |
||
64 | { |
||
65 | user { |
||
66 | id |
||
67 | name |
||
68 | friends { |
||
69 | id |
||
70 | name |
||
71 | } |
||
72 | } |
||
73 | user { |
||
74 | id |
||
75 | age |
||
76 | friends { |
||
77 | id |
||
78 | age |
||
79 | } |
||
80 | } |
||
81 | }')->getResponseData(); |
||
82 | $this->assertEquals(['data' => ['user' => [ |
||
83 | 'id' => '1', |
||
84 | 'name' => 'John', |
||
85 | 'age' => 30, |
||
86 | 'friends' => [ |
||
87 | [ |
||
88 | 'id' => 2, |
||
89 | 'name' => 'Friend 1', |
||
90 | 'age' => 31, |
||
91 | ], |
||
92 | [ |
||
93 | 'id' => 3, |
||
94 | 'name' => 'Friend 2', |
||
95 | 'age' => 32, |
||
96 | ], |
||
97 | ] |
||
98 | ]]], $response); |
||
99 | } |
||
100 | } |