Conditions | 1 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 50 |
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 |
||
101 | public function testForms(): void |
||
102 | { |
||
103 | Dropdown::counter(0); |
||
104 | |||
105 | $form = <<<HTML |
||
106 | <form class="px-4 py-3"> |
||
107 | <div class="form-group"> |
||
108 | <label for="exampleDropdownFormEmail1">Email address</label> |
||
109 | <input type="email" class="form-control" id="exampleDropdownFormEmail1" placeholder="[email protected]"> |
||
110 | </div> |
||
111 | <div class="form-group"> |
||
112 | <label for="exampleDropdownFormPassword1">Password</label> |
||
113 | <input type="password" class="form-control" id="exampleDropdownFormPassword1" placeholder="Password"> |
||
114 | </div> |
||
115 | <div class="form-check"> |
||
116 | <input type="checkbox" class="form-check-input" id="dropdownCheck"> |
||
117 | <label class="form-check-label" for="dropdownCheck"> |
||
118 | Remember me |
||
119 | </label> |
||
120 | </div> |
||
121 | <button type="submit" class="btn btn-primary">Sign in</button> |
||
122 | </form> |
||
123 | HTML; |
||
124 | |||
125 | $html = Dropdown::widget() |
||
126 | ->items([ |
||
127 | $form, |
||
128 | '-', |
||
129 | ['label' => 'New around here? Sign up', 'url' => '#'], |
||
130 | ['label' => 'Forgot password?', 'url' => '#'] |
||
131 | ]) |
||
132 | ->render(); |
||
133 | |||
134 | $expected = <<<HTML |
||
135 | <div id="w0-dropdown" class="dropdown-menu"><form class="px-4 py-3"> |
||
136 | <div class="form-group"> |
||
137 | <label for="exampleDropdownFormEmail1">Email address</label> |
||
138 | <input type="email" class="form-control" id="exampleDropdownFormEmail1" placeholder="[email protected]"> |
||
139 | </div> |
||
140 | <div class="form-group"> |
||
141 | <label for="exampleDropdownFormPassword1">Password</label> |
||
142 | <input type="password" class="form-control" id="exampleDropdownFormPassword1" placeholder="Password"> |
||
143 | </div> |
||
144 | <div class="form-check"> |
||
145 | <input type="checkbox" class="form-check-input" id="dropdownCheck"> |
||
146 | <label class="form-check-label" for="dropdownCheck"> |
||
147 | Remember me |
||
148 | </label> |
||
149 | </div> |
||
150 | <button type="submit" class="btn btn-primary">Sign in</button> |
||
151 | </form> |
||
152 | <div class="dropdown-divider"></div> |
||
153 | <a class="dropdown-item" href="#">New around here? Sign up</a> |
||
154 | <a class="dropdown-item" href="#">Forgot password?</a></div> |
||
155 | HTML; |
||
156 | |||
157 | $this->assertEqualsWithoutLE($expected, $html); |
||
158 | } |
||
160 |