| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 |
||
| 16 | public function actionsDataProvider(): array |
||
| 17 | { |
||
| 18 | return [ |
||
| 19 | // #0, the first case - simple header |
||
| 20 | [ |
||
| 21 | function (): object { |
||
| 22 | // setup |
||
| 23 | unset($_GET['create-button']); |
||
| 24 | $listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 25 | $listBuilder->setCustomHeaderActions('custom header actions'); |
||
| 26 | return $listBuilder; |
||
| 27 | }, |
||
| 28 | function ($result): void { |
||
| 29 | // asserting method |
||
| 30 | $this->assertStringContainsString('<form', $result); |
||
| 31 | $this->assertStringContainsString('</form>', $result); |
||
| 32 | $this->assertStringContainsString('method="post"', $result); |
||
| 33 | $this->assertStringContainsString('custom header actions', $result); |
||
| 34 | } |
||
| 35 | ], |
||
| 36 | // #1, the second case - full header |
||
| 37 | [ |
||
| 38 | function (): object { |
||
| 39 | // setup |
||
| 40 | $_GET['create-button'] = 1; |
||
| 41 | $listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 42 | $listBuilder->setCustomHeaderActions('custom header actions'); |
||
| 43 | return $listBuilder; |
||
| 44 | }, |
||
| 45 | function ($result): void { |
||
| 46 | // asserting method |
||
| 47 | $this->assertStringContainsString('<form', $result); |
||
| 48 | $this->assertStringContainsString('</form>', $result); |
||
| 49 | $this->assertStringContainsString('method="post"', $result); |
||
| 50 | $this->assertStringContainsString('custom header actions', $result); |
||
| 51 | } |
||
| 52 | ], |
||
| 53 | // #2, the third case - simple header |
||
| 54 | [ |
||
| 55 | function (): object { |
||
| 56 | // setup |
||
| 57 | $_GET['create-button'] = 1; |
||
| 58 | $listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter([])); |
||
| 59 | $listBuilder->setCustomHeaderActions('custom header actions'); |
||
| 60 | return $listBuilder; |
||
| 61 | }, |
||
| 62 | function ($result): void { |
||
| 63 | // asserting method |
||
| 64 | $this->assertStringNotContainsString('<form', $result); |
||
| 65 | $this->assertStringNotContainsString('</form>', $result); |
||
| 66 | $this->assertStringNotContainsString('method="post"', $result); |
||
| 67 | $this->assertStringNotContainsString('custom header actions', $result); |
||
| 68 | } |
||
| 94 |