| Conditions | 1 |
| Paths | 1 |
| Total Lines | 71 |
| Code Lines | 41 |
| 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 |
||
| 159 | private function getLocationFieldSet() |
||
| 160 | { |
||
| 161 | // Field set |
||
| 162 | $fieldSet = new Web\FieldSetElement('location', 'Location'); |
||
| 163 | |||
| 164 | // Select box with no multi selection and with no option groups |
||
| 165 | $select1 = new Web\SelectElement('country', 'I live in:'); |
||
| 166 | $select1->setOptions( |
||
| 167 | [ |
||
| 168 | ['label' => 'Hungary', 'value' => 'hu'], |
||
| 169 | ['label' => 'Germany', 'value' => 'de', 'checked' => true], |
||
| 170 | ['label' => 'Austria', 'value' => 'at'], |
||
| 171 | ] |
||
| 172 | ); |
||
| 173 | |||
| 174 | // Select box with no multi selection and WITH option groups |
||
| 175 | $select2 = new Web\SelectElement('dream', 'I\'d like live in:'); |
||
| 176 | $select2->setOptions( |
||
| 177 | [ |
||
| 178 | ['label' => 'Anywhere', 'value' => '*'], |
||
| 179 | ['label' => 'Hungary', 'value' => 'hu', 'group' => 'Europe'], |
||
| 180 | ['label' => 'USA', 'value' => 'us', 'group' => 'America'], |
||
| 181 | ['label' => 'Germany', 'value' => 'de', 'group' => 'Europe'], |
||
| 182 | ['label' => 'Austria', 'value' => 'at', 'group' => 'Europe'], |
||
| 183 | ['label' => 'Canada', 'value' => 'ca', 'group' => 'America'], |
||
| 184 | ['label' => 'Switzerland', 'value' => 'ch', 'group' => 'Europe', 'checked' => true], |
||
| 185 | ['label' => 'France', 'value' => 'fr', 'group' => 'Europe'], |
||
| 186 | ['label' => 'Spain', 'value' => 'es', 'group' => 'Europe'], |
||
| 187 | ['label' => 'Japan', 'value' => 'jp', 'group' => 'Asia'], |
||
| 188 | ] |
||
| 189 | ) |
||
| 190 | ->setErrors( |
||
| 191 | [ |
||
| 192 | 'This has some errors.', |
||
| 193 | 'And also has a major problem.' |
||
| 194 | ] |
||
| 195 | ); |
||
| 196 | |||
| 197 | // Select box WITH multi selection. |
||
| 198 | $select3 = new Web\SelectElement('past', 'I\'ve already lived in:'); |
||
| 199 | $select3->setOptions( |
||
| 200 | [ |
||
| 201 | ['label' => 'Hungary', 'value' => 'hu', 'group' => 'Europe', 'checked' => true], |
||
| 202 | ['label' => 'USA', 'value' => 'us', 'group' => 'America'], |
||
| 203 | ['label' => 'Germany', 'value' => 'de', 'group' => 'Europe', 'checked' => true], |
||
| 204 | ['label' => 'Austria', 'value' => 'at', 'group' => 'Europe'], |
||
| 205 | ['label' => 'Canada', 'value' => 'ca', 'group' => 'America'], |
||
| 206 | ['label' => 'Switzerland', 'value' => 'ch', 'group' => 'Europe'], |
||
| 207 | ['label' => 'France', 'value' => 'fr', 'group' => 'Europe'], |
||
| 208 | ['label' => 'Spain', 'value' => 'es', 'group' => 'Europe'], |
||
| 209 | ['label' => 'Japan', 'value' => 'jp', 'group' => 'Asia'], |
||
| 210 | ] |
||
| 211 | ) |
||
| 212 | ->setAttributes( |
||
| 213 | [ |
||
| 214 | 'multiple' => true, |
||
| 215 | 'size' => 10 |
||
| 216 | ] |
||
| 217 | ); |
||
| 218 | |||
| 219 | // Assign elements to the field set |
||
| 220 | $fieldSet->setNodes( |
||
| 221 | [ |
||
| 222 | $select1, |
||
| 223 | $select2, |
||
| 224 | $select3 |
||
| 225 | ] |
||
| 226 | ); |
||
| 227 | |||
| 228 | return $fieldSet; |
||
| 229 | } |
||
| 230 | } |
||
| 231 |
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: