| Conditions | 1 |
| Paths | 1 |
| Total Lines | 79 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 customActionsDataProvider(): array |
||
| 137 | { |
||
| 138 | $setup = function (): object { |
||
| 139 | // setup method |
||
| 140 | $listBuilder = new CommonListBuilder($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 | return [ |
||
| 154 | // #0, listingForm |
||
| 155 | [ |
||
| 156 | $setup, |
||
| 157 | function ($result): void { |
||
| 158 | // asserting method |
||
| 159 | $this->assertStringContainsString('!1!', $result); |
||
| 160 | $this->assertStringContainsString('!2!', $result); |
||
| 161 | } |
||
| 162 | ], |
||
| 163 | // #1, listingForm, no custom buttons |
||
| 164 | [ |
||
| 165 | function (): object { |
||
| 166 | // setup method |
||
| 167 | return new CommonListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 168 | }, |
||
| 169 | $assert |
||
| 170 | ], |
||
| 171 | // #2, listingForm, no custom buttons |
||
| 172 | [ |
||
| 173 | function (): object { |
||
| 174 | // setup method |
||
| 175 | return new CommonListBuilder([ |
||
| 176 | 'id' => [ |
||
| 177 | 'title' => 'Some id field' |
||
| 178 | ] |
||
| 179 | ], new FakeAdapter($this->getRecords())); |
||
| 180 | }, |
||
| 181 | $assert |
||
| 182 | ], |
||
| 183 | // #3, listingForm, no custom buttons |
||
| 184 | [ |
||
| 185 | function (): object { |
||
| 186 | // setup method |
||
| 187 | return new CommonListBuilder([ |
||
| 188 | 'id' => [ |
||
| 189 | 'title' => 'Some id field' |
||
| 190 | ] |
||
| 191 | ], new FakeAdapter($this->getRecords())); |
||
| 192 | }, |
||
| 193 | function (string $result) use ($assert) { |
||
| 194 | $assert($result); |
||
| 195 | |||
| 196 | $this->assertStringContainsString('Some id field', $result); |
||
| 197 | $this->assertStringContainsString('>1<', $result); |
||
| 198 | $this->assertStringContainsString('>2<', $result); |
||
| 199 | } |
||
| 200 | ], |
||
| 201 | // #4, listingForm, default buttons |
||
| 202 | [ |
||
| 203 | function (): object { |
||
| 204 | // setup method |
||
| 205 | $_GET['update-button'] = 1; |
||
| 206 | $_GET['create-button'] = 1; |
||
| 207 | return new CommonListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 208 | }, |
||
| 209 | function (string $result) use ($assert) { |
||
| 210 | $assert($result); |
||
| 211 | |||
| 212 | $this->assertStringContainsString('>id<', $result); |
||
| 213 | $this->assertStringContainsString('>1<', $result); |
||
| 214 | $this->assertStringContainsString('>2<', $result); |
||
| 215 | } |
||
| 241 |