Conditions | 1 |
Paths | 1 |
Total Lines | 124 |
Code Lines | 68 |
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 |
||
163 | public function commonBehaviourDataProvider(): array |
||
164 | { |
||
165 | $setup = function (): object { |
||
166 | // setup method |
||
167 | $listBuilder = new CommonListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
168 | |||
169 | $listBuilder->setCustomActions('!{id}!'); |
||
170 | |||
171 | return $listBuilder; |
||
172 | }; |
||
173 | |||
174 | $assert = function ($result): void { |
||
175 | // asserting method |
||
176 | $this->assertStringNotContainsString('!1!', $result); |
||
177 | $this->assertStringNotContainsString('!2!', $result); |
||
178 | }; |
||
179 | |||
180 | $headerData = [ |
||
181 | 'id' => [ |
||
182 | 'title' => 'Some id field' |
||
183 | ] |
||
184 | ]; |
||
185 | |||
186 | return [ |
||
187 | // #0, listingForm |
||
188 | [ |
||
189 | $setup, |
||
190 | function ($result): void { |
||
191 | // asserting method |
||
192 | $this->assertStringContainsStrings([ |
||
193 | '!1!', |
||
194 | '!2!' |
||
195 | ], $result); |
||
196 | } |
||
197 | ], |
||
198 | // #1, listingForm, no custom buttons |
||
199 | [ |
||
200 | function (): object { |
||
201 | // setup method |
||
202 | return new CommonListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
203 | }, |
||
204 | $assert |
||
205 | ], |
||
206 | // #2, listingForm, no custom buttons |
||
207 | [ |
||
208 | function () use ($headerData): object { |
||
209 | // setup method |
||
210 | return new CommonListBuilder($headerData, new FakeAdapter($this->getRecords())); |
||
211 | }, |
||
212 | $assert |
||
213 | ], |
||
214 | // #3, listingForm, no custom buttons |
||
215 | [ |
||
216 | function () use ($headerData): object { |
||
217 | // setup method |
||
218 | return new CommonListBuilder($headerData, new FakeAdapter($this->getRecords())); |
||
219 | }, |
||
220 | function (string $result) use ($assert) { |
||
221 | $assert($result); |
||
222 | |||
223 | $this->assertStringContainsStrings([ |
||
224 | 'Some id field', |
||
225 | '>1<', |
||
226 | '>2<' |
||
227 | ], $result); |
||
228 | } |
||
229 | ], |
||
230 | // #4, listingForm, default buttons |
||
231 | [ |
||
232 | function (): object { |
||
233 | // setup method |
||
234 | $_GET['update-button'] = 1; |
||
235 | $_GET['create-button'] = 1; |
||
236 | return new CommonListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
237 | }, |
||
238 | function (string $result) use ($assert) { |
||
239 | $assert($result); |
||
240 | |||
241 | $this->assertStringContainsStrings([ |
||
242 | '>id<', |
||
243 | '>1<', |
||
244 | '>2<' |
||
245 | ], $result); |
||
246 | } |
||
247 | ], |
||
248 | // #5, listingForm, custom title and description |
||
249 | [ |
||
250 | function (): object { |
||
251 | // setup method |
||
252 | $listBuilder = new CommonListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
253 | $listBuilder->listTitle = 'List Title'; |
||
254 | $listBuilder->listDescription = 'List Description'; |
||
255 | return $listBuilder; |
||
256 | }, |
||
257 | function (string $result) use ($assert) { |
||
258 | $assert($result); |
||
259 | |||
260 | $this->assertStringContainsStrings([ |
||
261 | '>id<', |
||
262 | '>1<', |
||
263 | '>2<', |
||
264 | 'List Title', |
||
265 | 'List Description' |
||
266 | ], $result); |
||
267 | } |
||
268 | ], |
||
269 | // #6, listingForm, default title and description |
||
270 | [ |
||
271 | function (): object { |
||
272 | // setup method |
||
273 | return new CommonListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
274 | }, |
||
275 | function (string $result) use ($assert) { |
||
276 | $assert($result); |
||
277 | |||
278 | $this->assertStringContainsStrings( |
||
279 | [ |
||
280 | '>id<', |
||
281 | '>1<', |
||
282 | '>2<', |
||
283 | 'Список записей', |
||
284 | 'Выберите необходимое действие' |
||
285 | ], |
||
286 | $result); |
||
287 | } |
||
313 |