| Conditions | 2 |
| Paths | 1 |
| Total Lines | 52 |
| 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 |
||
| 16 | public function build(SchemaConfig $config) |
||
| 17 | { |
||
| 18 | $config->setQuery( |
||
| 19 | new ObjectType([ |
||
| 20 | 'fields' => [ |
||
| 21 | new Field([ |
||
| 22 | 'name' => 'items', |
||
| 23 | 'type' => new ListType(new ObjectType([ |
||
| 24 | 'fields' => [ |
||
| 25 | 'id' => new NonNullType(new IdType()), |
||
| 26 | new Field([ |
||
| 27 | 'name' => 'custom', |
||
| 28 | 'type' => new ObjectType([ |
||
| 29 | 'fields' => [ |
||
| 30 | 'value' => new StringType() |
||
| 31 | ], |
||
| 32 | ]), |
||
| 33 | 'args' => [ |
||
| 34 | 'argX' => [ |
||
| 35 | 'type' => new NonNullType(new InputObjectType([ |
||
| 36 | 'fields' => [ |
||
| 37 | 'x' => new NonNullType(new StringType()) |
||
| 38 | ] |
||
| 39 | ])) |
||
| 40 | ] |
||
| 41 | ], |
||
| 42 | 'resolve' => function($source, $args) { |
||
| 43 | $x = isset($args['argX']['x']) ? $args['argX']['x'] : Issue99Test::BUG_EXISTS_VALUE; |
||
| 44 | |||
| 45 | return [ |
||
| 46 | 'value' => $x |
||
| 47 | ]; |
||
| 48 | } |
||
| 49 | ]) |
||
| 50 | ], |
||
| 51 | ])), |
||
| 52 | 'args' => [ |
||
| 53 | 'example' => new StringType() |
||
| 54 | ], |
||
| 55 | 'resolve' => function () { |
||
| 56 | return [ |
||
| 57 | ['id' => 1], |
||
| 58 | ['id' => 2], |
||
| 59 | ['id' => 3], |
||
| 60 | ['id' => 4], |
||
| 61 | ]; |
||
| 62 | } |
||
| 63 | ]) |
||
| 64 | ] |
||
| 65 | ]) |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | } |