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