| Conditions | 1 |
| Paths | 1 |
| Total Lines | 67 |
| 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 |
||
| 43 | public function testNullableResolving($query, $expected) |
||
| 44 | { |
||
| 45 | $schema = new Schema([ |
||
| 46 | 'query' => new ObjectType([ |
||
| 47 | 'name' => 'RootQuery', |
||
| 48 | 'fields' => [ |
||
| 49 | 'nonNullScalar' => [ |
||
| 50 | 'type' => new NonNullType(new IntType()), |
||
| 51 | 'resolve' => function () { |
||
| 52 | return null; |
||
| 53 | }, |
||
| 54 | ], |
||
| 55 | 'nonNullList' => [ |
||
| 56 | 'type' => new NonNullType(new ListType(new IntType())), |
||
| 57 | 'resolve' => function () { |
||
| 58 | return null; |
||
| 59 | } |
||
| 60 | ], |
||
| 61 | 'user' => [ |
||
| 62 | 'type' => new NonNullType(new ObjectType([ |
||
| 63 | 'name' => 'User', |
||
| 64 | 'fields' => [ |
||
| 65 | 'id' => new NonNullType(new IdType()), |
||
| 66 | 'name' => new StringType(), |
||
| 67 | ] |
||
| 68 | ])), |
||
| 69 | 'resolve' => function () { |
||
| 70 | return [ |
||
| 71 | 'id' => new uid('6cfb044c-9c0a-4ddd-9ef8-a0b940818db3'), |
||
| 72 | 'name' => 'Alex' |
||
| 73 | ]; |
||
| 74 | } |
||
| 75 | ], |
||
| 76 | 'nonNullListOfNpnNull' => [ |
||
| 77 | 'type' => new NonNullType(new ListType(new NonNullType(new IntType()))), |
||
| 78 | 'resolve' => function () { |
||
| 79 | return [1, null]; |
||
| 80 | } |
||
| 81 | ], |
||
| 82 | 'nonNullArgument' => [ |
||
| 83 | 'args' => [ |
||
| 84 | 'ids' => new NonNullType(new ListType(new IntType())) |
||
| 85 | ], |
||
| 86 | 'type' => new IntType(), |
||
| 87 | 'resolve' => function () { |
||
| 88 | return 1; |
||
| 89 | } |
||
| 90 | ], |
||
| 91 | 'nonNullArgument2' => [ |
||
| 92 | 'args' => [ |
||
| 93 | 'ids' => new NonNullType(new ListType(new NonNullType(new IntType()))) |
||
| 94 | ], |
||
| 95 | 'type' => new IntType(), |
||
| 96 | 'resolve' => function () { |
||
| 97 | return 1; |
||
| 98 | } |
||
| 99 | ], |
||
| 100 | ] |
||
| 101 | ]) |
||
| 102 | ]); |
||
| 103 | |||
| 104 | $processor = new Processor($schema); |
||
| 105 | $processor->processPayload($query); |
||
| 106 | $result = $processor->getResponseData(); |
||
| 107 | |||
| 108 | $this->assertEquals($expected, $result); |
||
| 109 | } |
||
| 110 | |||
| 223 |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.