| Conditions | 10 |
| Paths | 15 |
| Total Lines | 114 |
| Code Lines | 52 |
| 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 |
||
| 192 | function userDataDefine(&$row, $db, $config) |
||
| 193 | { |
||
| 194 | static $board_timezone = null, $avatar_dir, $attachment_type, $phpbb_avatar_upload_path, $phpbb_avatar_salt; |
||
| 195 | |||
| 196 | // Try to only do this collection once |
||
| 197 | if (!isset($board_timezone)) |
||
| 198 | { |
||
| 199 | $request2 = $db->query(" |
||
| 200 | SELECT |
||
| 201 | config_value |
||
| 202 | FROM {$config->from_prefix}config |
||
| 203 | WHERE config_name = 'board_timezone' |
||
| 204 | LIMIT 1" |
||
| 205 | ); |
||
| 206 | list ($board_timezone) = $db->fetch_row($request2); |
||
| 207 | $db->free_result($request2); |
||
| 208 | |||
| 209 | // Find out where uploaded avatars go |
||
| 210 | $request2 = $db->query(" |
||
| 211 | SELECT |
||
| 212 | value |
||
| 213 | FROM {$config->to_prefix}settings |
||
| 214 | WHERE variable = 'custom_avatar_dir' |
||
| 215 | LIMIT 1" |
||
| 216 | ); |
||
| 217 | list ($avatar_dir) = $db->fetch_row($request2); |
||
| 218 | $attachment_type = '1'; |
||
| 219 | $db->free_result($request2); |
||
| 220 | |||
| 221 | // Not custom so ... |
||
| 222 | if (empty($avatar_dir)) |
||
| 223 | { |
||
| 224 | $request2 = $db->query(" |
||
| 225 | SELECT |
||
| 226 | value |
||
| 227 | FROM {$config->to_prefix}settings |
||
| 228 | WHERE variable = 'attachmentUploadDir' |
||
| 229 | LIMIT 1"); |
||
| 230 | list ($avatar_dir) = $db->fetch_row($request2); |
||
| 231 | $attachment_type = '0'; |
||
| 232 | $db->free_result($request2); |
||
| 233 | } |
||
| 234 | |||
| 235 | $request2 = $db->query(" |
||
| 236 | SELECT |
||
| 237 | config_value |
||
| 238 | FROM {$config->from_prefix}config |
||
| 239 | WHERE config_name = 'avatar_path' |
||
| 240 | LIMIT 1"); |
||
| 241 | $temp = $db->fetch_assoc($request2); |
||
| 242 | $phpbb_avatar_upload_path = $_POST['path_from'] . '/' . $temp['config_value']; |
||
| 243 | $db->free_result($request2); |
||
| 244 | |||
| 245 | $request2 = $db->query(" |
||
| 246 | SELECT |
||
| 247 | config_value |
||
| 248 | FROM {$config->from_prefix}config |
||
| 249 | WHERE config_name = 'avatar_salt' |
||
| 250 | LIMIT 1"); |
||
| 251 | $temp = $db->fetch_assoc($request2); |
||
| 252 | $phpbb_avatar_salt = $temp['config_value']; |
||
| 253 | $db->free_result($request2); |
||
| 254 | } |
||
| 255 | |||
| 256 | // Fix signatures |
||
| 257 | $row['signature'] = phpbb_replace_bbc(unParse($row['signature'], $row['user_sig_bbcode_uid'])); |
||
| 258 | unset($row['user_sig_bbcode_uid']); |
||
| 259 | |||
| 260 | // Convert time zones to time offset in hours |
||
| 261 | $dt = new \DateTime('now', new \DateTimeZone($board_timezone)); |
||
| 262 | $offset_from = $dt->getOffset(); |
||
| 263 | $timestamp = $dt->getTimestamp(); |
||
| 264 | $offset_to = $dt->setTimezone(new \DateTimezone($row['time_offset'] ?? $board_timezone))->setTimestamp($timestamp)->getOffset(); |
||
| 265 | $row['time_offset'] = $offset_to / 3600 - $offset_from / 3600; |
||
| 266 | |||
| 267 | // Determine Avatars |
||
| 268 | // AVATAR_UPLOAD => 'avatar.driver.upload', or 1 |
||
| 269 | // AVATAR_REMOTE => 'avatar.driver.remote', or 2 |
||
| 270 | // AVATAR_GALLERY => 'avatar.driver.local', or 3 |
||
| 271 | if (empty($row['user_avatar_type'])) |
||
| 272 | { |
||
| 273 | $row['avatar'] = ''; |
||
| 274 | } |
||
| 275 | elseif (($row['user_avatar_type'] === 'avatar.driver.upload' || $row['user_avatar_type'] === '1') |
||
| 276 | && !empty($row['avatar'])) |
||
| 277 | { |
||
| 278 | // If the avatar type is uploaded, copy avatar with the correct name. |
||
| 279 | $phpbb_avatar_ext = substr(strchr($row['avatar'], '.'), 1); |
||
| 280 | $elk_avatar_filename = 'avatar_' . $row['id_member'] . strrchr($row['avatar'], '.'); |
||
| 281 | |||
| 282 | if (file_exists($phpbb_avatar_upload_path . '/' . $phpbb_avatar_salt . '_' . $row['id_member'] . '.' . $phpbb_avatar_ext)) |
||
| 283 | { |
||
| 284 | @copy($phpbb_avatar_upload_path . '/' . $phpbb_avatar_salt . '_' . $row['id_member'] . '.' . $phpbb_avatar_ext, $avatar_dir . '/' . $elk_avatar_filename); |
||
| 285 | } |
||
| 286 | else |
||
| 287 | { |
||
| 288 | @copy($phpbb_avatar_upload_path . '/' . $row['avatar'], $avatar_dir . '/' . $elk_avatar_filename); |
||
| 289 | } |
||
| 290 | |||
| 291 | $id = $row['id_member']; |
||
| 292 | $db_filename = substr(addslashes($elk_avatar_filename), 0, 255); |
||
| 293 | $db->query("INSERT INTO {$config->to_prefix}attachments |
||
| 294 | (id_msg, id_member, filename, attachment_type) |
||
| 295 | VALUES(0, '$id', '$db_filename', '$attachment_type')" |
||
| 296 | ); |
||
| 297 | |||
| 298 | $row['avatar'] = ''; |
||
| 299 | } |
||
| 300 | elseif ($row['user_avatar_type'] === 'avatar.driver.local' || $row['user_avatar_type'] === '3') |
||
| 301 | { |
||
| 302 | $row['avatar'] = substr('gallery/' . $row['avatar'], 0, 255); |
||
| 303 | } |
||
| 304 | |||
| 305 | unset($row['user_avatar_type']); |
||
| 306 | } |
||
| 350 |