| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 21 |
| 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 |
||
| 117 | public function testValidationFail() |
||
| 118 | { |
||
| 119 | $res = GraphQL::executeQuery( |
||
| 120 | $this->schema, |
||
| 121 | Utils::nowdoc(' |
||
| 122 | mutation UpdateBook( |
||
| 123 | $bookAttributes: BookAttributes |
||
| 124 | ) { |
||
| 125 | updateBook ( |
||
| 126 | bookAttributes: $bookAttributes |
||
| 127 | ) { |
||
| 128 | valid |
||
| 129 | suberrors { |
||
| 130 | bookAttributes { |
||
| 131 | suberrors { |
||
| 132 | title { |
||
| 133 | code |
||
| 134 | msg |
||
| 135 | } |
||
| 136 | author { |
||
| 137 | code |
||
| 138 | msg |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 | } |
||
| 143 | result |
||
| 144 | } |
||
| 145 | } |
||
| 146 | '), |
||
| 147 | [], |
||
| 148 | null, |
||
| 149 | [ |
||
| 150 | 'bookAttributes' => [ |
||
| 151 | 'title' => 'The Catcher in the Rye', |
||
| 152 | 'author' => 4, |
||
| 153 | ], |
||
| 154 | ] |
||
| 155 | ); |
||
| 156 | |||
| 157 | static::assertEquals( |
||
| 158 | [ |
||
| 159 | 'valid' => false, |
||
| 160 | 'suberrors' => |
||
| 161 | [ |
||
| 162 | 'bookAttributes' => |
||
| 163 | [ |
||
| 164 | 'suberrors' => |
||
| 165 | [ |
||
| 166 | 'title' => |
||
| 167 | [ |
||
| 168 | 'code' => 1, |
||
| 169 | 'msg' => 'book title must be less than 10 chaacters', |
||
| 170 | ], |
||
| 171 | 'author' => |
||
| 172 | [ |
||
| 173 | 'code' => 'unknownAuthor', |
||
| 174 | 'msg' => 'We have no record of that author', |
||
| 175 | ], |
||
| 176 | ], |
||
| 177 | ], |
||
| 178 | ], |
||
| 179 | 'result' => null, |
||
| 180 | ], |
||
| 181 | $res->data['updateBook'] |
||
| 182 | ); |
||
| 183 | |||
| 184 | static::assertFalse($res->data['updateBook']['valid']); |
||
| 185 | } |
||
| 240 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.