Conditions | 1 |
Paths | 1 |
Total Lines | 103 |
Code Lines | 80 |
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 |
||
17 | public function testRender(): void |
||
18 | { |
||
19 | Accordion::counter(0); |
||
20 | |||
21 | $html = Accordion::widget() |
||
22 | ->items([ |
||
23 | [ |
||
24 | 'label' => 'Collapsible Group Item #1', |
||
25 | 'content' => [ |
||
26 | 'test content1', |
||
27 | 'test content2' |
||
28 | ], |
||
29 | ], |
||
30 | [ |
||
31 | 'label' => 'Collapsible Group Item #2', |
||
32 | 'content' => 'Das ist das Haus vom Nikolaus', |
||
33 | 'contentOptions' => [ |
||
34 | 'class' => 'testContentOptions' |
||
35 | ], |
||
36 | 'options' => [ |
||
37 | 'class' => 'testClass', |
||
38 | 'id' => 'testId' |
||
39 | ], |
||
40 | 'footer' => 'Footer' |
||
41 | ], |
||
42 | [ |
||
43 | 'label' => '<h1>Collapsible Group Item #3</h1>', |
||
44 | 'content' => [ |
||
45 | '<h2>test content1</h2>', |
||
46 | '<h2>test content2</h2>' |
||
47 | ], |
||
48 | 'contentOptions' => [ |
||
49 | 'class' => 'testContentOptions2' |
||
50 | ], |
||
51 | 'options' => [ |
||
52 | 'class' => 'testClass2', |
||
53 | 'id' => 'testId2' |
||
54 | ], |
||
55 | 'encode' => false, |
||
56 | 'footer' => 'Footer2' |
||
57 | ], |
||
58 | [ |
||
59 | 'label' => '<h1>Collapsible Group Item #4</h1>', |
||
60 | 'content' => [ |
||
61 | '<h2>test content1</h2>', |
||
62 | '<h2>test content2</h2>' |
||
63 | ], |
||
64 | 'contentOptions' => [ |
||
65 | 'class' => 'testContentOptions3' |
||
66 | ], |
||
67 | 'options' => [ |
||
68 | 'class' => 'testClass3', |
||
69 | 'id' => 'testId3' |
||
70 | ], |
||
71 | 'encode' => true, |
||
72 | 'footer' => 'Footer3' |
||
73 | ], |
||
74 | ]) |
||
75 | ->render(); |
||
76 | |||
77 | $expectedHtml = <<<HTML |
||
78 | <div id="w0-accordion" class="accordion"> |
||
79 | <div class="card"><div id="w0-accordion-collapse0-heading" class="card-header"><h5 class="mb-0"><button type="button" id="w1-button" class="btn-link btn" data-toggle="collapse" data-target="#w0-accordion-collapse0" aria-expanded="true" aria-controls="w0-accordion-collapse0">Collapsible Group Item #1</button> |
||
80 | </h5></div> |
||
81 | <div id="w0-accordion-collapse0" class="collapse show" aria-labelledby="w0-accordion-collapse0-heading" data-parent="#w0-accordion"> |
||
82 | <ul class="list-group"> |
||
83 | <li class="list-group-item">test content1</li> |
||
84 | <li class="list-group-item">test content2</li> |
||
85 | </ul> |
||
86 | |||
87 | </div></div> |
||
88 | <div id="testId" class="testClass card"><div id="w0-accordion-collapse1-heading" class="card-header"><h5 class="mb-0"><button type="button" id="w2-button" class="btn-link btn" data-toggle="collapse" data-target="#w0-accordion-collapse1" aria-expanded="false" aria-controls="w0-accordion-collapse1">Collapsible Group Item #2</button> |
||
89 | </h5></div> |
||
90 | <div id="w0-accordion-collapse1" class="testContentOptions collapse" aria-labelledby="w0-accordion-collapse1-heading" data-parent="#w0-accordion"> |
||
91 | <div class="card-body">Das ist das Haus vom Nikolaus</div> |
||
92 | |||
93 | <div class="card-footer">Footer</div> |
||
94 | </div></div> |
||
95 | <div id="testId2" class="testClass2 card"><div id="w0-accordion-collapse2-heading" class="card-header"><h5 class="mb-0"><button type="button" id="w3-button" class="btn-link btn" data-toggle="collapse" data-target="#w0-accordion-collapse2" aria-expanded="false" aria-controls="w0-accordion-collapse2"><h1>Collapsible Group Item #3</h1></button> |
||
96 | </h5></div> |
||
97 | <div id="w0-accordion-collapse2" class="testContentOptions2 collapse" aria-labelledby="w0-accordion-collapse2-heading" data-parent="#w0-accordion"> |
||
98 | <ul class="list-group"> |
||
99 | <li class="list-group-item"><h2>test content1</h2></li> |
||
100 | <li class="list-group-item"><h2>test content2</h2></li> |
||
101 | </ul> |
||
102 | |||
103 | <div class="card-footer">Footer2</div> |
||
104 | </div></div> |
||
105 | <div id="testId3" class="testClass3 card"><div id="w0-accordion-collapse3-heading" class="card-header"><h5 class="mb-0"><button type="button" id="w4-button" class="btn-link btn" data-toggle="collapse" data-target="#w0-accordion-collapse3" aria-expanded="false" aria-controls="w0-accordion-collapse3"><h1>Collapsible Group Item #4</h1></button> |
||
106 | </h5></div> |
||
107 | <div id="w0-accordion-collapse3" class="testContentOptions3 collapse" aria-labelledby="w0-accordion-collapse3-heading" data-parent="#w0-accordion"> |
||
108 | <ul class="list-group"> |
||
109 | <li class="list-group-item"><h2>test content1</h2></li> |
||
110 | <li class="list-group-item"><h2>test content2</h2></li> |
||
111 | </ul> |
||
112 | |||
113 | <div class="card-footer">Footer3</div> |
||
114 | </div></div> |
||
115 | </div> |
||
116 | |||
117 | HTML; |
||
118 | |||
119 | $this->assertEqualsWithoutLE($expectedHtml, $html); |
||
120 | } |
||
219 |