| Conditions | 2 |
| Paths | 1 |
| Total Lines | 69 |
| Code Lines | 39 |
| 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 | 'connections' => [ |
||
| 23 | 'type' => new ObjectType([ |
||
| 24 | 'name' => 'ConnectionType', |
||
| 25 | 'fields' => [ |
||
| 26 | 'pageInfo' => new ObjectType([ |
||
| 27 | 'name' => 'PageInfo', |
||
| 28 | 'fields' => [ |
||
| 29 | 'totalEdges' => new IntType(), |
||
| 30 | 'cursors' => [ |
||
| 31 | 'type' => new ListType(new StringType()), |
||
| 32 | 'args' => [ |
||
| 33 | 'size' => new NonNullType(new IntType()), |
||
| 34 | ], |
||
| 35 | 'resolve' => function ($source, $args) { |
||
| 36 | $res = []; |
||
| 37 | foreach (range(1, $args['size']) as $i) { |
||
| 38 | $res[] = 'Cursor #' . $i; |
||
| 39 | } |
||
| 40 | |||
| 41 | return $res; |
||
| 42 | } |
||
| 43 | ], |
||
| 44 | ] |
||
| 45 | ]) |
||
| 46 | ] |
||
| 47 | ]), |
||
| 48 | 'args' => [ |
||
| 49 | 'first' => new IntType(), |
||
| 50 | ], |
||
| 51 | 'resolve' => function () { |
||
| 52 | return [ |
||
| 53 | 'pageInfo' => [ |
||
| 54 | 'totalEdges' => 10, |
||
| 55 | 'cursors' => [] |
||
| 56 | ] |
||
| 57 | ]; |
||
| 58 | } |
||
| 59 | ] |
||
| 60 | ] |
||
| 61 | ]) |
||
| 62 | ]); |
||
| 63 | $processor = new Processor($schema); |
||
| 64 | $response = $processor->processPayload(' |
||
| 65 | query ($size: Int) { |
||
| 66 | connections(first: 0) { |
||
| 67 | pageInfo { |
||
| 68 | totalEdges |
||
| 69 | cursors (size: $size) |
||
| 70 | } |
||
| 71 | } |
||
| 72 | }', |
||
| 73 | [ |
||
| 74 | 'size' => 2, |
||
| 75 | ])->getResponseData(); |
||
| 76 | $this->assertEquals(['data' => ['connections' => [ |
||
| 77 | 'pageInfo' => [ |
||
| 78 | 'totalEdges' => 10, |
||
| 79 | 'cursors' => [ |
||
| 80 | 'Cursor #1', 'Cursor #2' |
||
| 81 | ] |
||
| 82 | ], |
||
| 83 | ]]], $response); |
||
| 84 | } |
||
| 85 | } |