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