| 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 |
||
| 144 | public function customActionsDataProvider(): array |
||
| 145 | { |
||
| 146 | $setup = function (): object { |
||
| 147 | // setup method |
||
| 148 | $listBuilder = new ListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 149 | |||
| 150 | $listBuilder->setCustomActions('!{id}!'); |
||
| 151 | |||
| 152 | return $listBuilder; |
||
| 153 | }; |
||
| 154 | |||
| 155 | $assert = function ($result): void { |
||
| 156 | // asserting method |
||
| 157 | $this->assertStringNotContainsString('!1!', $result); |
||
| 158 | $this->assertStringNotContainsString('!2!', $result); |
||
| 159 | }; |
||
| 160 | |||
| 161 | return [ |
||
| 162 | // #0, simpleListingForm |
||
| 163 | [ |
||
| 164 | $setup, |
||
| 165 | $assert, |
||
| 166 | 'simpleListingForm' |
||
| 167 | ], |
||
| 168 | // #1, listingForm |
||
| 169 | [ |
||
| 170 | $setup, |
||
| 171 | function ($result): void { |
||
| 172 | // asserting method |
||
| 173 | $this->assertStringContainsString('!1!', $result); |
||
| 174 | $this->assertStringContainsString('!2!', $result); |
||
| 175 | }, |
||
| 176 | 'listingForm' |
||
| 177 | ], |
||
| 178 | // #2, listingForm, no custom buttons |
||
| 179 | [ |
||
| 180 | function (): object { |
||
| 181 | // setup method |
||
| 182 | return new ListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 183 | }, |
||
| 184 | $assert, |
||
| 185 | 'listingForm' |
||
| 186 | ], |
||
| 187 | // #3, listingForm, no custom buttons |
||
| 188 | [ |
||
| 189 | function (): object { |
||
| 190 | // setup method |
||
| 191 | return new ListBuilder([ |
||
| 192 | 'id' => [ |
||
| 193 | 'title' => 'Some id field' |
||
| 194 | ] |
||
| 195 | ], new FakeAdapter($this->getRecords())); |
||
| 196 | }, |
||
| 197 | $assert, |
||
| 198 | 'listingForm' |
||
| 199 | ], |
||
| 200 | // #4, listingForm, no custom buttons |
||
| 201 | [ |
||
| 202 | function (): object { |
||
| 203 | // setup method |
||
| 204 | return new ListBuilder([ |
||
| 205 | 'id' => [ |
||
| 206 | 'title' => 'Some id field' |
||
| 207 | ] |
||
| 208 | ], new FakeAdapter($this->getRecords())); |
||
| 209 | }, |
||
| 210 | function (string $result) use ($assert) { |
||
| 211 | $assert($result); |
||
| 212 | |||
| 213 | $this->assertStringContainsString('Some id field', $result); |
||
| 214 | $this->assertStringContainsString('>1<', $result); |
||
| 215 | $this->assertStringContainsString('>2<', $result); |
||
| 216 | }, |
||
| 217 | 'listingForm' |
||
| 218 | ], |
||
| 219 | // #5, simpleListingForm, no custom buttons |
||
| 220 | [ |
||
| 221 | function (): object { |
||
| 222 | // setup method |
||
| 223 | return new ListBuilder([ |
||
| 224 | 'title' => [ |
||
| 225 | 'title' => 'Title field' |
||
| 226 | ] |
||
| 227 | ], new FakeAdapter($this->getRecords())); |
||
| 228 | }, |
||
| 229 | function (string $result) use ($assert) { |
||
| 230 | $assert($result); |
||
| 231 | |||
| 232 | $this->assertStringContainsString('Title field', $result); |
||
| 233 | }, |
||
| 234 | 'simpleListingForm' |
||
| 235 | ], |
||
| 236 | // #6, listingForm, default buttons |
||
| 237 | [ |
||
| 238 | function (): object { |
||
| 239 | // setup method |
||
| 240 | $_GET['update-button'] = 1; |
||
| 241 | $_GET['create-button'] = 1; |
||
| 242 | return new ListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 243 | }, |
||
| 244 | function (string $result) use ($assert) { |
||
| 245 | $assert($result); |
||
| 246 | |||
| 247 | $this->assertStringContainsString('>id<', $result); |
||
| 248 | $this->assertStringContainsString('>1<', $result); |
||
| 249 | $this->assertStringContainsString('>2<', $result); |
||
| 250 | }, |
||
| 251 | 'simpleListingForm' |
||
| 252 | ] |
||
| 278 |