| Conditions | 2 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 testIntCodeType() : void |
||
| 20 | { |
||
| 21 | $schema = new Schema([ |
||
| 22 | 'query' => new ObjectType(['name' => 'Query']), |
||
| 23 | 'mutation' => new ObjectType([ |
||
| 24 | 'name' => 'Mutation', |
||
| 25 | 'fields' => function () { |
||
| 26 | return [ |
||
| 27 | 'updateBook' => new ValidatedFieldDefinition([ |
||
| 28 | 'name' => 'updateBook', |
||
| 29 | 'type' => Type::boolean(), |
||
| 30 | 'args' => [ |
||
| 31 | 'bookId' => [ |
||
| 32 | 'type' => Type::id(), |
||
| 33 | 'validate' => function ($bookId) { |
||
| 34 | return empty($bookId) ? 1 : 0; |
||
| 35 | }, |
||
| 36 | ], |
||
| 37 | ], |
||
| 38 | 'resolve' => static function ($value) : bool { |
||
| 39 | return !!$value; |
||
| 40 | }, |
||
| 41 | ]), |
||
| 42 | ]; |
||
| 43 | }, |
||
| 44 | ]), |
||
| 45 | ]); |
||
| 46 | |||
| 47 | $res = GraphQL::executeQuery( |
||
| 48 | $schema, |
||
| 49 | Utils::nowdoc(' |
||
| 50 | mutation UpdateBook( |
||
| 51 | $bookId:ID |
||
| 52 | ) { |
||
| 53 | updateBook (bookId: $bookId) { |
||
| 54 | valid |
||
| 55 | fields { |
||
| 56 | bookId { |
||
| 57 | code |
||
| 58 | msg |
||
| 59 | } |
||
| 60 | } |
||
| 61 | result |
||
| 62 | } |
||
| 63 | } |
||
| 64 | '), |
||
| 65 | [], |
||
| 66 | null, |
||
| 67 | ['bookId' => null] |
||
| 68 | ); |
||
| 69 | |||
| 70 | static::assertEmpty($res->errors); |
||
| 71 | static::assertEquals($res->data['updateBook']['fields']['bookId']['code'], 1); |
||
| 72 | } |
||
| 133 |