| 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 |
||
| 33 | public function actionsDataProvider(): array |
||
| 34 | { |
||
| 35 | return [ |
||
| 36 | // #0, the first case - simple header |
||
| 37 | [ |
||
| 38 | function (): object { |
||
| 39 | // setup |
||
| 40 | unset($_GET['create-button']); |
||
| 41 | $listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 42 | $listBuilder->setCustomHeaderActions('custom header actions'); |
||
| 43 | return $listBuilder; |
||
| 44 | }, |
||
| 45 | function (string $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 | // #1, the second case - full header |
||
| 54 | [ |
||
| 55 | function (): object { |
||
| 56 | // setup |
||
| 57 | $_GET['create-button'] = 1; |
||
| 58 | $listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter($this->getRecords())); |
||
| 59 | $listBuilder->setCustomHeaderActions('custom header actions'); |
||
| 60 | return $listBuilder; |
||
| 61 | }, |
||
| 62 | function (string $result): void { |
||
| 63 | // asserting method |
||
| 64 | $this->assertStringContainsString('<form', $result); |
||
| 65 | $this->assertStringContainsString('</form>', $result); |
||
| 66 | $this->assertStringContainsString('method="post"', $result); |
||
| 67 | $this->assertStringContainsString('custom header actions', $result); |
||
| 68 | } |
||
| 69 | ], |
||
| 70 | // #2, the third case - simple header |
||
| 71 | [ |
||
| 72 | function (): object { |
||
| 73 | // setup |
||
| 74 | $_GET['create-button'] = 1; |
||
| 75 | $listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter([])); |
||
| 76 | $listBuilder->setCustomHeaderActions('custom header actions'); |
||
| 77 | return $listBuilder; |
||
| 78 | }, |
||
| 79 | function (string $result): void { |
||
| 80 | // asserting method |
||
| 81 | $this->assertStringNotContainsString('<form', $result); |
||
| 82 | $this->assertStringNotContainsString('</form>', $result); |
||
| 83 | $this->assertStringNotContainsString('method="post"', $result); |
||
| 84 | $this->assertStringNotContainsString('custom header actions', $result); |
||
| 85 | } |
||
| 111 |