| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 28 |
| 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 testInvalidNullableList() |
||
| 17 | { |
||
| 18 | $schema = new Schema([ |
||
| 19 | 'query' => new ObjectType([ |
||
| 20 | 'name' => 'RootQuery', |
||
| 21 | 'fields' => [ |
||
| 22 | 'list' => [ |
||
| 23 | 'type' => new StringType(), |
||
| 24 | 'args' => [ |
||
| 25 | 'ids' => new ListType(new NonNullType(new IdType())) |
||
| 26 | ], |
||
| 27 | 'resolve' => function () { |
||
| 28 | return 'item'; |
||
| 29 | } |
||
| 30 | ], |
||
| 31 | ] |
||
| 32 | ]) |
||
| 33 | ]); |
||
| 34 | |||
| 35 | |||
| 36 | $processor = new Processor($schema); |
||
| 37 | $processor->processPayload( |
||
| 38 | 'query getList($ids: [ID!]) { list(ids: $ids) }', |
||
| 39 | [ |
||
| 40 | 'ids' => [1, 12, null] |
||
| 41 | ] |
||
| 42 | ); |
||
| 43 | $this->assertEquals(['data' => ['list' => 'item']], $processor->getResponseData()); |
||
| 44 | |||
| 45 | $processor->getExecutionContext()->clearErrors(); |
||
| 46 | $processor->processPayload( |
||
| 47 | 'query getList($ids: [ID]) { list(ids: $ids) }', |
||
| 48 | [ |
||
| 49 | 'ids' => [1, 12, null] |
||
| 50 | ] |
||
| 51 | ); |
||
| 52 | $this->assertEquals( |
||
| 53 | [ |
||
| 54 | 'data' => ['list' => null], |
||
| 55 | 'errors' => [ |
||
| 56 | [ |
||
| 57 | 'message' => 'Invalid variable "ids" type, allowed type is "ID"', |
||
| 58 | 'locations' => [ |
||
| 59 | [ |
||
| 60 | 'line' => 1, |
||
| 61 | 'column' => 15 |
||
| 62 | ] |
||
| 63 | ] |
||
| 64 | ], |
||
| 65 | ] |
||
| 66 | ], |
||
| 67 | $processor->getResponseData()); |
||
| 68 | } |
||
| 69 | |||
| 146 |