| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 38 |
| 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 |
||
| 153 | private function getLocationFieldSet() |
||
| 154 | { |
||
| 155 | // Field set |
||
| 156 | $fieldSet = new Web\FieldSetElement('location', 'Location'); |
||
| 157 | |||
| 158 | // Select box with no multi selection and with no option groups |
||
| 159 | $select1 = new Web\SelectElement('country', 'I live in:'); |
||
| 160 | $select1->setOptions( |
||
| 161 | [ |
||
| 162 | ['label' => 'Hungary', 'value' => 'hu'], |
||
| 163 | ['label' => 'Germany', 'value' => 'de', 'checked' => true], |
||
| 164 | ['label' => 'Austria', 'value' => 'at'], |
||
| 165 | ] |
||
| 166 | ); |
||
| 167 | |||
| 168 | // Select box with no multi selection and WITH option groups |
||
| 169 | $select2 = new Web\SelectElement('dream', 'I\'d like live in:'); |
||
| 170 | $select2->setOptions( |
||
| 171 | [ |
||
| 172 | ['label' => 'Anywhere', 'value' => '*'], |
||
| 173 | ['label' => 'Hungary', 'value' => 'hu', 'group' => 'Europe'], |
||
| 174 | ['label' => 'USA', 'value' => 'us', 'group' => 'America'], |
||
| 175 | ['label' => 'Germany', 'value' => 'de', 'group' => 'Europe'], |
||
| 176 | ['label' => 'Austria', 'value' => 'at', 'group' => 'Europe'], |
||
| 177 | ['label' => 'Canada', 'value' => 'ca', 'group' => 'America'], |
||
| 178 | ['label' => 'Switzerland', 'value' => 'ch', 'group' => 'Europe', 'checked' => true], |
||
| 179 | ['label' => 'France', 'value' => 'fr', 'group' => 'Europe'], |
||
| 180 | ['label' => 'Spain', 'value' => 'es', 'group' => 'Europe'], |
||
| 181 | ['label' => 'Japan', 'value' => 'jp', 'group' => 'Asia'], |
||
| 182 | ] |
||
| 183 | ); |
||
| 184 | |||
| 185 | // Select box WITH multi selection. |
||
| 186 | $select3 = new Web\SelectElement('past', 'I\'ve already lived in:'); |
||
| 187 | $select3->setOptions( |
||
| 188 | [ |
||
| 189 | ['label' => 'Hungary', 'value' => 'hu', 'group' => 'Europe', 'checked' => true], |
||
| 190 | ['label' => 'USA', 'value' => 'us', 'group' => 'America'], |
||
| 191 | ['label' => 'Germany', 'value' => 'de', 'group' => 'Europe', 'checked' => true], |
||
| 192 | ['label' => 'Austria', 'value' => 'at', 'group' => 'Europe'], |
||
| 193 | ['label' => 'Canada', 'value' => 'ca', 'group' => 'America'], |
||
| 194 | ['label' => 'Switzerland', 'value' => 'ch', 'group' => 'Europe'], |
||
| 195 | ['label' => 'France', 'value' => 'fr', 'group' => 'Europe'], |
||
| 196 | ['label' => 'Spain', 'value' => 'es', 'group' => 'Europe'], |
||
| 197 | ['label' => 'Japan', 'value' => 'jp', 'group' => 'Asia'], |
||
| 198 | ] |
||
| 199 | ) |
||
| 200 | ->setAttributes( |
||
| 201 | [ |
||
| 202 | 'multiple' => true, |
||
| 203 | 'size' => 10 |
||
| 204 | ] |
||
| 205 | ); |
||
| 206 | |||
| 207 | // Assign elements to the field set |
||
| 208 | $fieldSet->setNodes( |
||
| 209 | [ |
||
| 210 | $select1, |
||
| 211 | $select2, |
||
| 212 | $select3 |
||
| 213 | ] |
||
| 214 | ); |
||
| 215 | |||
| 216 | return $fieldSet; |
||
| 217 | } |
||
| 218 | } |
||
| 219 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: