| Conditions | 18 |
| Paths | 393 |
| Total Lines | 114 |
| Code Lines | 79 |
| 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 |
||
| 194 | function process_create_profile($user, $profile) { |
||
| 195 | $response1 = post_str('response1', true); |
||
| 196 | $response2 = post_str('response2', true); |
||
| 197 | $language = post_str('language', true); |
||
| 198 | |||
| 199 | if (recaptcha_private_key()) { |
||
| 200 | if (!boinc_recaptcha_isValidated(recaptcha_private_key())) { |
||
| 201 | $profile->response1 = $response1; |
||
| 202 | $profile->response2 = $response2; |
||
| 203 | show_profile_form($profile, |
||
| 204 | tra("Your ReCaptcha response was not correct. Please try again.") |
||
| 205 | ); |
||
| 206 | return; |
||
| 207 | } |
||
| 208 | } |
||
| 209 | if (!akismet_check($user, $response1)) { |
||
| 210 | $profile->response1 = $response1; |
||
| 211 | $profile->response2 = $response2; |
||
| 212 | show_profile_form($profile, |
||
| 213 | tra("Your first response was flagged as spam by the Akismet anti-spam system. Please modify your text and try again.") |
||
| 214 | ); |
||
| 215 | return; |
||
| 216 | } |
||
| 217 | if (!akismet_check($user, $response2)) { |
||
| 218 | $profile->response1 = $response1; |
||
| 219 | $profile->response2 = $response2; |
||
| 220 | show_profile_form($profile, |
||
| 221 | tra("Your second response was flagged as spam by the Akismet anti-spam system. Please modify your text and try again.") |
||
| 222 | ); |
||
| 223 | return; |
||
| 224 | } |
||
| 225 | |||
| 226 | if (isset($_POST['delete_pic'])) { |
||
| 227 | $delete_pic = $_POST['delete_pic']; |
||
| 228 | } else { |
||
| 229 | $delete_pic = "off"; |
||
| 230 | } |
||
| 231 | |||
| 232 | if (strlen($response1)==0 && |
||
| 233 | strlen($response2)==0 && |
||
| 234 | $delete_pic != "on" && |
||
| 235 | !is_uploaded_file($_FILES['picture']['tmp_name']) |
||
| 236 | ) { |
||
| 237 | error_page(tra("Your profile submission was empty.")); |
||
| 238 | exit(); |
||
| 239 | } |
||
| 240 | |||
| 241 | if ($delete_pic == "on") { |
||
| 242 | delete_user_pictures($profile->userid); |
||
| 243 | $profile->has_picture = false; |
||
| 244 | $profile->verification = 0; |
||
| 245 | } |
||
| 246 | |||
| 247 | $profile ? $has_picture = $profile->has_picture: $has_picture = false; |
||
| 248 | |||
| 249 | if (is_uploaded_file($_FILES['picture']['tmp_name'])) { |
||
| 250 | $has_picture = true; |
||
| 251 | if ($profile) $profile->verification = 0; |
||
| 252 | |||
| 253 | // echo "<br>Name: " . $_FILES['picture']['name']; |
||
| 254 | // echo "<br>Type: " . $_FILES['picture']['type']; |
||
| 255 | // echo "<br>Size: " . $_FILES['picture']['size']; |
||
| 256 | // echo "<br>Temp name: " . $_FILES['picture']['tmp_name']; |
||
| 257 | |||
| 258 | $images = getImages($_FILES['picture']['tmp_name']); |
||
| 259 | |||
| 260 | // Write the original image file to disk. |
||
| 261 | // TODO: define a constant for image quality. |
||
| 262 | ImageJPEG($images[0], IMAGE_PATH . $user->id . '.jpg'); |
||
| 263 | ImageJPEG($images[1], IMAGE_PATH . $user->id . '_sm.jpg'); |
||
| 264 | } |
||
| 265 | $response1 = sanitize_html($response1); |
||
| 266 | $response2 = sanitize_html($response2); |
||
| 267 | |||
| 268 | $has_picture = $has_picture?1:0; |
||
| 269 | if ($profile) { |
||
| 270 | $query = " response1 = '".BoincDb::escape_string($response1)."'," |
||
| 271 | ." response2 = '".BoincDb::escape_string($response2)."'," |
||
| 272 | ." language = '".BoincDb::escape_string($language)."'," |
||
| 273 | ." has_picture = $has_picture," |
||
| 274 | ." verification = $profile->verification" |
||
| 275 | ." WHERE userid = $user->id"; |
||
| 276 | $result = BoincProfile::update_aux($query); |
||
| 277 | if (!$result) { |
||
| 278 | error_page(tra("Could not update the profile: database error")); |
||
| 279 | } |
||
| 280 | } else { |
||
| 281 | $query = 'SET ' |
||
| 282 | ." userid=$user->id," |
||
| 283 | ." language = '".BoincDb::escape_string($language)."'," |
||
| 284 | ." response1 = '".BoincDb::escape_string($response1)."'," |
||
| 285 | ." response2 = '".BoincDb::escape_string($response2)."'," |
||
| 286 | ." has_picture = $has_picture," |
||
| 287 | ." recommend=0, " |
||
| 288 | ." reject=0, " |
||
| 289 | ." posts=0, " |
||
| 290 | ." uotd_time=0, " |
||
| 291 | ." verification=0"; |
||
| 292 | $result = BoincProfile::insert($query); |
||
| 293 | if (!$result) { |
||
| 294 | error_page(tra("Could not create the profile: database error")); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | $user->update("has_profile=1"); |
||
| 298 | |||
| 299 | page_head(tra("Profile saved")); |
||
| 300 | |||
| 301 | echo tra("Congratulations! Your profile was successfully entered into our database.") |
||
| 302 | ."<br><br>" |
||
| 303 | ."<a href=\"view_profile.php?userid=".$user->id."\">" |
||
| 304 | .tra("View your profile") |
||
| 305 | ."</a><br>" |
||
| 306 | ; |
||
| 307 | page_tail(); |
||
| 308 | } |
||
| 359 |