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