| Conditions | 28 |
| Paths | > 20000 |
| Total Lines | 130 |
| Lines | 130 |
| Ratio | 100 % |
| 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 namespace Xoopsmodules\smallworld; |
||
| 381 | View Code Duplication | public function ParsePubArray($updatesarray, $id) |
|
| 382 | { |
||
| 383 | global $xoopsUser, $xoopsTpl, $tpl, $xoopsModule, $xoopsTpl, $xoopsConfig; |
||
| 384 | $wm = []; |
||
| 385 | $check = new SmallWorldUser; |
||
| 386 | $dBase = new SmallWorldDB; |
||
| 387 | $profile = $xoopsUser ? $check->checkIfProfile($id) : 0; |
||
| 388 | $moduleHandler = xoops_getHandler('module'); |
||
| 389 | $module = $moduleHandler->getByDirname('smallworld'); |
||
| 390 | $configHandler = xoops_getHandler('config'); |
||
| 391 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 392 | |||
| 393 | $myavatar = $this->Gravatar($id); |
||
| 394 | $myavatarlink = smallworld_getAvatarLink($id, $myavatar); |
||
| 395 | $myavatar_size = smallworld_getImageSize(80, 100, $myavatarlink); |
||
| 396 | $myavatar_highwide = smallworld_imageResize($myavatar_size[0], $myavatar_size[1], 100); |
||
| 397 | $user_img = "<img src='" . smallworld_getAvatarLink($id, $myavatar) . "' id='smallworld_user_img' " . $myavatar_highwide . '>'; |
||
| 398 | |||
| 399 | $xoopsTpl->assign('myavatar', $myavatar); |
||
| 400 | $xoopsTpl->assign('myavatarlink', $myavatarlink); |
||
| 401 | $xoopsTpl->assign('myavatar_highwide', $myavatar_highwide); |
||
| 402 | $xoopsTpl->assign('avatar', $user_img); |
||
| 403 | |||
| 404 | if (!empty($updatesarray)) { |
||
| 405 | foreach ($updatesarray as $data) { |
||
| 406 | |||
| 407 | // Is update's user a friend ? |
||
| 408 | $frU = $check->friendcheck($id, $data['uid_fk']); |
||
| 409 | |||
| 410 | $USW = []; |
||
| 411 | $USW['posts'] = 0; |
||
| 412 | $USW['comments'] = 0; |
||
| 413 | |||
| 414 | if ($xoopsUser) { |
||
| 415 | if ($xoopsUser->isAdmin($xoopsModule->getVar('mid')) || $data['uid_fk'] == $id) { |
||
| 416 | $USW['posts'] = 1; |
||
| 417 | $USW['comments'] = 1; |
||
| 418 | $frU[0] = 2; |
||
| 419 | } else { |
||
| 420 | $USW = json_decode($dBase->GetSettings($data['uid_fk']), true); |
||
| 421 | } |
||
| 422 | } |
||
| 423 | |||
| 424 | if (!$xoopsUser) { |
||
| 425 | $USW = json_decode($dBase->GetSettings($data['uid_fk']), true); |
||
| 426 | } |
||
| 427 | |||
| 428 | $wm['msg_id'] = $data['msg_id']; |
||
| 429 | $wm['orimessage'] = (1 == $USW['posts'] || $profile >= 2) ? str_replace(["\r", "\n"], '', Smallworld_stripWordsKeepUrl($data['message'])) : ''; |
||
| 430 | $wm['message'] = (1 == $USW['posts'] || $profile >= 2) ? smallworld_tolink(htmlspecialchars_decode($data['message']), $data['uid_fk']) : _SMALLWORLD_MESSAGE_PRIVSETPOSTS; |
||
| 431 | $wm['message'] = Smallworld_cleanup($wm['message']); |
||
| 432 | $wm['created'] = smallworld_time_stamp($data['created']); |
||
| 433 | $wm['username'] = $data['username']; |
||
| 434 | $wm['uid_fk'] = $data['uid_fk']; |
||
| 435 | $wm['priv'] = $data['priv']; |
||
| 436 | $wm['avatar'] = $this->Gravatar($data['uid_fk']); |
||
| 437 | $wm['avatar_link'] = smallworld_getAvatarLink($data['uid_fk'], $wm['avatar']); |
||
| 438 | $wm['avatar_size'] = smallworld_getImageSize(80, 100, $wm['avatar_link']); |
||
| 439 | $wm['avatar_highwide'] = smallworld_imageResize($wm['avatar_size'][0], $wm['avatar_size'][1], 50); |
||
| 440 | $wm['vote_up'] = $this->countVotes('msg', 'up', $data['msg_id']); |
||
| 441 | $wm['vote_down'] = $this->countVotes('msg', 'down', $data['msg_id']); |
||
| 442 | $wm['sharelinkurl'] = XOOPS_URL . '/modules/smallworld/smallworldshare.php?ownerid=' . $data['uid_fk']; |
||
| 443 | $wm['sharelinkurl'] .= '&updid=' . $data['msg_id'] . ''; |
||
| 444 | $wm['usernameTitle'] = $wm['username'] . _SMALLWORLD_UPDATEONSITEMETA . $xoopsConfig['sitename']; |
||
| 445 | if (1 == $USW['posts'] || $profile >= 2) { |
||
| 446 | $wm['sharelink'] = $this->GetSharing($wm['msg_id'], $wm['priv']); |
||
| 447 | } else { |
||
| 448 | $wm['sharelink'] = $this->GetSharing($wm['msg_id'], 1); |
||
| 449 | } |
||
| 450 | |||
| 451 | if (1 == $USW['posts'] || $profile >= 2) { |
||
| 452 | $wm['sharediv'] = $this->GetSharingDiv($wm['msg_id'], $wm['priv'], $wm['sharelinkurl'], $wm['orimessage'], $wm['usernameTitle']); |
||
| 453 | } else { |
||
| 454 | $wm['sharediv'] = $this->GetSharingDiv($wm['msg_id'], 1, $wm['sharelinkurl'], $wm['orimessage'], $wm['usernameTitle']); |
||
| 455 | } |
||
| 456 | $wm['linkimage'] = XOOPS_URL . '/modules/smallworld/assets/images/link.png'; |
||
| 457 | $wm['permalink'] = XOOPS_URL . '/modules/smallworld/permalink.php?ownerid=' . $data['uid_fk'] . '&updid=' . $data['msg_id']; |
||
| 458 | $wm['commentsarray'] = $this->Comments($data['msg_id']); |
||
| 459 | |||
| 460 | if (2 == $frU[0] || 1 == $USW['posts']) { |
||
| 461 | $xoopsTpl->append('walldata', $wm); |
||
| 462 | } |
||
| 463 | |||
| 464 | if (!empty($wm['commentsarray'])) { |
||
| 465 | foreach ($wm['commentsarray'] as $cdata) { |
||
| 466 | // Is commentuser a friend ? |
||
| 467 | $frC = $check->friendcheck($id, $cdata['uid_fk']); |
||
| 468 | |||
| 469 | $USC = []; |
||
| 470 | $USC['posts'] = 0; |
||
| 471 | $USC['comments'] = 0; |
||
| 472 | |||
| 473 | if ($xoopsUser) { |
||
| 474 | if ($xoopsUser->isAdmin($xoopsModule->getVar('mid')) || $cdata['uid_fk'] == $id) { |
||
| 475 | $USC['posts'] = 1; |
||
| 476 | $USC['comments'] = 1; |
||
| 477 | $frC[0] = 2; |
||
| 478 | } else { |
||
| 479 | $USC = json_decode($dBase->GetSettings($cdata['uid_fk']), true); |
||
| 480 | } |
||
| 481 | } |
||
| 482 | |||
| 483 | if (!$xoopsUser) { |
||
| 484 | $USC = json_decode($dBase->GetSettings($cdata['uid_fk']), true); |
||
| 485 | } |
||
| 486 | |||
| 487 | $wc['msg_id_fk'] = $cdata['msg_id_fk']; |
||
| 488 | $wc['com_id'] = $cdata['com_id']; |
||
| 489 | $wc['comment'] = (1 == $USC['comments'] || $profile >= 2) ? smallworld_tolink(htmlspecialchars_decode($cdata['comment']), $cdata['uid_fk']) : _SMALLWORLD_MESSAGE_PRIVSETCOMMENTS; |
||
| 490 | $wc['comment'] = Smallworld_cleanup($wc['comment']); |
||
| 491 | $wc['time'] = smallworld_time_stamp($cdata['created']); |
||
| 492 | $wc['username'] = $cdata['username']; |
||
| 493 | $wc['uid'] = $cdata['uid_fk']; |
||
| 494 | $wc['myavatar'] = $this->Gravatar($id); |
||
| 495 | $wc['myavatar_link'] = $myavatarlink; |
||
| 496 | $wc['avatar_size'] = smallworld_getImageSize(80, 100, $wc['myavatar_link']); |
||
| 497 | $wc['avatar_highwide'] = smallworld_imageResize($wc['avatar_size'][0], $wc['avatar_size'][1], 35); |
||
| 498 | $wc['cface'] = $this->Gravatar($cdata['uid_fk']); |
||
| 499 | $wc['avatar_link'] = smallworld_getAvatarLink($cdata['uid_fk'], $wc['cface']); |
||
| 500 | $wc['vote_up'] = $this->countVotesCom('com', 'up', $cdata['msg_id_fk'], $cdata['com_id']); |
||
| 501 | $wc['vote_down'] = $this->countVotesCom('com', 'down', $cdata['msg_id_fk'], $cdata['com_id']); |
||
| 502 | |||
| 503 | if (2 == $frC[0] || 1 == $USC['comments']) { |
||
| 504 | $xoopsTpl->append('comm', $wc); |
||
| 505 | } |
||
| 506 | } |
||
| 507 | } |
||
| 508 | } |
||
| 509 | } |
||
| 510 | } |
||
| 511 | } |
||
| 512 |