Conditions | 3 |
Paths | 1 |
Total Lines | 66 |
Code Lines | 42 |
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 | protected function setUp() |
||
44 | { |
||
45 | $this->personType = new ObjectType([ |
||
46 | 'name' => 'Person', |
||
47 | 'fields' => [ |
||
48 | 'firstName' => [ |
||
49 | 'type' => Type::string(), |
||
50 | 'phoneNumbers' => [ |
||
51 | 'type' => Type::listOf(Type::string()), |
||
52 | ], |
||
53 | ], |
||
54 | ], |
||
55 | ]); |
||
56 | |||
57 | $this->bookAttributesInputType = new InputObjectType([ |
||
58 | 'name' => 'BookAttributes', |
||
59 | 'fields' => [ |
||
60 | 'title' => [ |
||
61 | 'type' => Type::string(), |
||
62 | 'description' => 'Enter a book title, no more than 10 characters in length', |
||
63 | 'validate' => static function (string $title) { |
||
64 | if (strlen($title) > 10) { |
||
65 | return [1, 'book title must be less than 10 chaacters']; |
||
66 | } |
||
67 | return 0; |
||
68 | }, |
||
69 | ], |
||
70 | 'author' => [ |
||
71 | 'type' => Type::id(), |
||
72 | 'description' => 'Provide a valid author id', |
||
73 | 'errorCodes' => [ |
||
74 | 'unknownAuthor', |
||
75 | 'authorDeceased', |
||
76 | ], |
||
77 | 'validate' => function (string $authorId) { |
||
78 | if (! isset($this->data['people'][$authorId])) { |
||
79 | return ['unknownAuthor', 'We have no record of that author']; |
||
80 | } |
||
81 | return 0; |
||
82 | }, |
||
83 | ], |
||
84 | ], |
||
85 | ]); |
||
86 | |||
87 | $this->query = new ObjectType(['name' => 'Query']); |
||
88 | |||
89 | $this->schema = new Schema([ |
||
90 | 'query' => $this->query, |
||
91 | 'mutation' => new ObjectType([ |
||
92 | 'name' => 'Mutation', |
||
93 | 'fields' => function () { |
||
94 | return [ |
||
95 | 'updateBook' => new ValidatedFieldDefinition([ |
||
96 | 'name' => 'updateBook', |
||
97 | 'type' => Type::boolean(), |
||
98 | 'args' => [ |
||
99 | 'bookAttributes' => [ |
||
100 | 'type' => $this->bookAttributesInputType, |
||
101 | ], |
||
102 | ], |
||
103 | 'resolve' => static function ($value, $args) : bool { |
||
104 | // ... |
||
105 | // do update |
||
106 | // ... |
||
107 | |||
108 | return true; |
||
109 | }, |
||
240 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.