| Conditions | 2 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 38 |
| 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 |
||
| 42 | protected function setUp() |
||
| 43 | { |
||
| 44 | $this->personType = new ObjectType([ |
||
| 45 | 'name' => 'Person', |
||
| 46 | 'fields' => [ |
||
| 47 | 'firstName' => [ |
||
| 48 | 'type' => Type::string(), |
||
| 49 | 'phoneNumbers' => [ |
||
| 50 | 'type' => Type::listOf(Type::string()), |
||
| 51 | ], |
||
| 52 | ], |
||
| 53 | ], |
||
| 54 | ]); |
||
| 55 | |||
| 56 | $this->bookType = new ObjectType([ |
||
| 57 | 'name' => 'Book', |
||
| 58 | 'fields' => [ |
||
| 59 | 'title' => [ |
||
| 60 | 'type' => Type::string(), |
||
| 61 | 'resolve' => static function ($book) { |
||
| 62 | return $book['title']; |
||
| 63 | }, |
||
| 64 | ], |
||
| 65 | 'author' => [ |
||
| 66 | 'type' => $this->personType, |
||
| 67 | 'resolve' => static function ($book) { |
||
| 68 | return $book['author']; |
||
| 69 | }, |
||
| 70 | ], |
||
| 71 | ], |
||
| 72 | ]); |
||
| 73 | |||
| 74 | $this->query = new ObjectType(['name' => 'Query']); |
||
| 75 | |||
| 76 | $this->schema = new Schema([ |
||
| 77 | 'query' => $this->query, |
||
| 78 | 'mutation' => new ObjectType([ |
||
| 79 | 'name' => 'Mutation', |
||
| 80 | 'fields' => function () { |
||
| 81 | return [ |
||
| 82 | 'updateBook' => new ValidatedFieldDefinition([ |
||
| 83 | 'name' => 'updateBook', |
||
| 84 | 'type' => $this->bookType, |
||
| 85 | 'args' => [ |
||
| 86 | 'bookId' => [ |
||
| 87 | 'type' => Type::id(), |
||
| 88 | 'errorCodes' => ['bookNotFound'], |
||
| 89 | 'validate' => function ($bookId) { |
||
| 90 | if (isset($this->data['books'][$bookId])) { |
||
| 91 | return 0; |
||
| 92 | } |
||
| 93 | |||
| 94 | return ['bookNotFound', 'Unknown book!']; |
||
| 95 | }, |
||
| 96 | ], |
||
| 97 | ], |
||
| 98 | 'resolve' => static function ($value, $args) : bool { |
||
| 99 | return true; |
||
| 100 | }, |
||
| 139 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.