Conditions | 1 |
Paths | 1 |
Total Lines | 108 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 2 |
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 |
||
176 | public function customActionsDataProvider(): array |
||
177 | { |
||
178 | $setup = function (): object { |
||
179 | // setup method |
||
180 | $listBuilder = new ListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
181 | |||
182 | $listBuilder->setCustomActions('!{id}!'); |
||
183 | |||
184 | return $listBuilder; |
||
185 | }; |
||
186 | |||
187 | $assert = function ($result): void { |
||
188 | // asserting method |
||
189 | $this->assertStringNotContainsString('!1!', $result); |
||
190 | $this->assertStringNotContainsString('!2!', $result); |
||
191 | }; |
||
192 | |||
193 | return [ |
||
194 | // #0, simpleListingForm |
||
195 | [ |
||
196 | $setup, |
||
197 | $assert, |
||
198 | 'simpleListingForm' |
||
199 | ], |
||
200 | // #1, listingForm |
||
201 | [ |
||
202 | $setup, |
||
203 | function ($result): void { |
||
204 | // asserting method |
||
205 | $this->assertStringContainsString('!1!', $result); |
||
206 | $this->assertStringContainsString('!2!', $result); |
||
207 | }, |
||
208 | 'listingForm' |
||
209 | ], |
||
210 | // #2, listingForm, no custom buttons |
||
211 | [ |
||
212 | function (): object { |
||
213 | // setup method |
||
214 | return new ListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
215 | }, |
||
216 | $assert, |
||
217 | 'listingForm' |
||
218 | ], |
||
219 | // #3, listingForm, no custom buttons |
||
220 | [ |
||
221 | function (): object { |
||
222 | // setup method |
||
223 | return new ListBuilder([ |
||
224 | 'id' => [ |
||
225 | 'title' => 'Some id field' |
||
226 | ] |
||
227 | ], new FakeAdapter($this->getRecords())); |
||
228 | }, |
||
229 | $assert, |
||
230 | 'listingForm' |
||
231 | ], |
||
232 | // #4, listingForm, no custom buttons |
||
233 | [ |
||
234 | function (): object { |
||
235 | // setup method |
||
236 | return new ListBuilder([ |
||
237 | 'id' => [ |
||
238 | 'title' => 'Some id field' |
||
239 | ] |
||
240 | ], new FakeAdapter($this->getRecords())); |
||
241 | }, |
||
242 | function (string $result) use ($assert) { |
||
243 | $assert($result); |
||
244 | |||
245 | $this->assertStringContainsString('Some id field', $result); |
||
246 | $this->assertStringContainsString('>1<', $result); |
||
247 | $this->assertStringContainsString('>2<', $result); |
||
248 | }, |
||
249 | 'listingForm' |
||
250 | ], |
||
251 | // #5, simpleListingForm, no custom buttons |
||
252 | [ |
||
253 | function (): object { |
||
254 | // setup method |
||
255 | return new ListBuilder([ |
||
256 | 'title' => [ |
||
257 | 'title' => 'Title field' |
||
258 | ] |
||
259 | ], new FakeAdapter($this->getRecords())); |
||
260 | }, |
||
261 | function (string $result) use ($assert) { |
||
262 | $assert($result); |
||
263 | |||
264 | $this->assertStringContainsString('Title field', $result); |
||
265 | }, |
||
266 | 'simpleListingForm' |
||
267 | ], |
||
268 | // #6, listingForm, default buttons |
||
269 | [ |
||
270 | function (): object { |
||
271 | // setup method |
||
272 | $_GET['update-button'] = 1; |
||
273 | $_GET['create-button'] = 1; |
||
274 | return new ListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
275 | }, |
||
276 | function (string $result) use ($assert) { |
||
277 | $assert($result); |
||
278 | |||
279 | $this->assertStringContainsString('>id<', $result); |
||
280 | $this->assertStringContainsString('>1<', $result); |
||
281 | $this->assertStringContainsString('>2<', $result); |
||
282 | }, |
||
283 | 'simpleListingForm' |
||
284 | ] |
||
310 |