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