| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 36 |
| 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 |
||
| 18 | public function testInternalVariableArgument() |
||
| 19 | { |
||
| 20 | |||
| 21 | |||
| 22 | $schema = new Schema([ |
||
| 23 | 'query' => new ObjectType([ |
||
| 24 | 'name' => 'RootQuery', |
||
| 25 | 'fields' => [ |
||
| 26 | 'hello' => new StringType(), |
||
| 27 | ] |
||
| 28 | ]), |
||
| 29 | 'mutation' => new ObjectType([ |
||
| 30 | 'name' => 'RootMutation', |
||
| 31 | 'fields' => [ |
||
| 32 | 'createMeeting' => [ |
||
| 33 | 'type' => new ObjectType([ |
||
| 34 | 'name' => 'Meeting', |
||
| 35 | 'fields' => [ |
||
| 36 | 'id' => new IdType(), |
||
| 37 | 'name' => new StringType(), |
||
| 38 | ] |
||
| 39 | ]), |
||
| 40 | 'args' => [ |
||
| 41 | 'name' => new StringType(), |
||
| 42 | 'related_beans' => new ListType(new ObjectType([ |
||
| 43 | 'name' => 'RelatedBeanInputType', |
||
| 44 | 'fields' => [ |
||
| 45 | 'id' => new IntType(), |
||
| 46 | 'module' => new StringType(), |
||
| 47 | ] |
||
| 48 | ])) |
||
| 49 | ], |
||
| 50 | 'resolve' => function ($source, $args) { |
||
| 51 | return [ |
||
| 52 | 'id' => '1', |
||
| 53 | 'name' => sprintf('Meeting with %d beans', count($args['related_beans'])), |
||
| 54 | ]; |
||
| 55 | } |
||
| 56 | ] |
||
| 57 | ] |
||
| 58 | ]) |
||
| 59 | ]); |
||
| 60 | $processor = new Processor($schema); |
||
| 61 | $response = $processor->processPayload(' |
||
| 62 | mutation ($related_beans: RelatedBeanInputType) { |
||
| 63 | createMeeting(name: "Meeting 1", related_beans: $related_beans) { |
||
| 64 | id, |
||
| 65 | name |
||
| 66 | } |
||
| 67 | }', |
||
| 68 | [ |
||
| 69 | "related_beans" => [ |
||
| 70 | ["module" => "contacts", "id" => "5cc6be5b-fb86-2671-e2c0-55e749882d29"], |
||
| 71 | ["module" => "contacts", "id" => "2a135003-3765-af3f-bc54-55e7497e77aa"], |
||
| 72 | |||
| 73 | ] |
||
| 74 | ])->getResponseData(); |
||
| 75 | $this->assertEquals(['data' => ['createMeeting' => [ |
||
| 76 | 'id' => '1', |
||
| 77 | 'name' => 'Meeting with 2 beans' |
||
| 78 | ]]], $response); |
||
| 79 | } |
||
| 80 | } |