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