| 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 |
||
| 139 | $content = $listBuilder->listingForm(); |
||
| 140 | |||
| 141 | // assertions |
||
| 142 | $this->runAssertions($asserts, $content); |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Asserting that string contains substrings |
||
| 147 | * |
||
| 148 | * @param array $needles |
||
| 149 | * @param string $haystack |
||
| 150 | */ |
||
| 151 | private function assertStringContainsStrings(array $needles, string $haystack): void |
||
| 152 | { |
||
| 153 | foreach ($needles as $needle) { |
||
| 154 | $this->assertStringContainsString($needle, $haystack); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Testing data provider |
||
| 160 | * |
||
| 161 | * @return array testing data |
||
| 162 | */ |
||
| 163 | public function commonBehaviourDataProvider(): array |
||
| 164 | { |
||
| 165 | $setup = function (): object { |
||
| 166 | // setup method |
||
| 167 | $listBuilder = new CommonListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 168 | |||
| 169 | $listBuilder->setCustomActions('!{id}!'); |
||
| 170 | |||
| 171 | return $listBuilder; |
||
| 172 | }; |
||
| 173 | |||
| 174 | $assert = function ($result): void { |
||
| 175 | // asserting method |
||
| 176 | $this->assertStringNotContainsString('!1!', $result); |
||
| 177 | $this->assertStringNotContainsString('!2!', $result); |
||
| 178 | }; |
||
| 179 | |||
| 180 | $headerData = [ |
||
| 181 | 'id' => [ |
||
| 182 | 'title' => 'Some id field' |
||
| 183 | ] |
||
| 184 | ]; |
||
| 185 | |||
| 186 | return [ |
||
| 187 | // #0, listingForm |
||
| 188 | [ |
||
| 189 | $setup, |
||
| 190 | function ($result): void { |
||
| 191 | // asserting method |
||
| 192 | $this->assertStringContainsStrings([ |
||
| 193 | '!1!', |
||
| 194 | '!2!' |
||
| 195 | ], $result); |
||
| 196 | } |
||
| 197 | ], |
||
| 198 | // #1, listingForm, no custom buttons |
||
| 199 | [ |
||
| 200 | function (): object { |
||
| 201 | // setup method |
||
| 202 | return new CommonListBuilder($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 203 | }, |
||
| 204 | $assert |
||
| 205 | ], |
||
| 206 | // #2, listingForm, no custom buttons |
||
| 207 | [ |
||
| 208 | function () use ($headerData): object { |
||
| 209 | // setup method |
||
| 210 | return new CommonListBuilder($headerData, new FakeAdapter($this->getRecords())); |
||
| 211 | }, |
||
| 212 | $assert |
||
| 213 | ], |
||
| 214 | // #3, listingForm, no custom buttons |
||
| 215 | [ |
||
| 216 | function () use ($headerData): object { |
||
| 217 | // setup method |
||
| 218 | return new CommonListBuilder($headerData, new FakeAdapter($this->getRecords())); |
||
| 313 |