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