| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 31 |
| 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 |
||
| 19 | public function testDefaultEnum() |
||
| 20 | { |
||
| 21 | $enumType = new EnumType([ |
||
| 22 | 'name' => 'InternalStatus', |
||
| 23 | 'values' => [ |
||
| 24 | [ |
||
| 25 | 'name' => 1, |
||
| 26 | 'value' => 'ACTIVE' |
||
| 27 | ], |
||
| 28 | [ |
||
| 29 | 'name' => 0, |
||
| 30 | 'value' => 'DISABLED' |
||
| 31 | ], |
||
| 32 | ] |
||
| 33 | ]); |
||
| 34 | $schema = new Schema([ |
||
| 35 | 'query' => new ObjectType([ |
||
| 36 | 'name' => 'RootQuery', |
||
| 37 | 'fields' => [ |
||
| 38 | 'stringQuery' => [ |
||
| 39 | 'type' => new StringType(), |
||
| 40 | 'args' => [ |
||
| 41 | 'statObject' => new InputObjectType([ |
||
| 42 | 'name' => 'StatObjectType', |
||
| 43 | 'fields' => [ |
||
| 44 | 'status' => [ |
||
| 45 | 'type' => $enumType, |
||
| 46 | 'default' => 1 |
||
| 47 | ], |
||
| 48 | 'level' => new NonNullType(new IntType()) |
||
| 49 | ] |
||
| 50 | ]) |
||
| 51 | ], |
||
| 52 | 'resolve' => function ($source, $args) { |
||
| 53 | return sprintf('Result with level %s and status %s', |
||
| 54 | $args['statObject']['level'], $args['statObject']['status'] |
||
| 55 | ); |
||
| 56 | }, |
||
| 57 | ], |
||
| 58 | ] |
||
| 59 | ]) |
||
| 60 | ]); |
||
| 61 | |||
| 62 | $processor = new Processor($schema); |
||
| 63 | $processor->processPayload('{ stringQuery(statObject: { level: 1 }) }'); |
||
| 64 | $result = $processor->getResponseData(); |
||
| 65 | |||
| 66 | $this->assertEquals(['data' => [ |
||
| 67 | 'stringQuery' => 'Result with level 1 and status ACTIVE' |
||
| 68 | ]], $result); |
||
| 69 | } |
||
| 70 | |||
| 71 | } |