We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 13 |
| Paths | 192 |
| Total Lines | 84 |
| Code Lines | 55 |
| 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 declare(strict_types=1); |
||
| 29 | public function build(AbstractSmrPlayer $player, Template $template): void { |
||
| 30 | $session = Session::getInstance(); |
||
| 31 | |||
| 32 | Menu::messages(); |
||
| 33 | |||
| 34 | $folderID = $this->folderID; |
||
| 35 | |||
| 36 | $db = Database::getInstance(); |
||
| 37 | $whereClause = 'WHERE game_id = ' . $db->escapeNumber($player->getGameID()); |
||
| 38 | if ($folderID == MSG_SENT) { |
||
| 39 | $whereClause .= ' AND sender_id = ' . $db->escapeNumber($player->getAccountID()) . ' |
||
| 40 | AND message_type_id = ' . $db->escapeNumber(MSG_PLAYER) . ' |
||
| 41 | AND sender_delete = ' . $db->escapeBoolean(false); |
||
| 42 | } else { |
||
| 43 | $whereClause .= ' AND account_id = ' . $db->escapeNumber($player->getAccountID()) . ' |
||
| 44 | AND message_type_id = ' . $db->escapeNumber($folderID) . ' |
||
| 45 | AND receiver_delete = ' . $db->escapeBoolean(false); |
||
| 46 | } |
||
| 47 | |||
| 48 | $messageBox = []; |
||
| 49 | if ($folderID == MSG_SENT) { |
||
| 50 | $messageBox['UnreadMessages'] = 0; |
||
| 51 | } else { |
||
| 52 | $dbResult = $db->read('SELECT count(*) as count |
||
| 53 | FROM message ' . $whereClause . ' |
||
| 54 | AND msg_read = ' . $db->escapeBoolean(false)); |
||
| 55 | $messageBox['UnreadMessages'] = $dbResult->record()->getInt('count'); |
||
| 56 | } |
||
| 57 | $dbResult = $db->read('SELECT count(*) as count FROM message ' . $whereClause); |
||
| 58 | $messageBox['TotalMessages'] = $dbResult->record()->getInt('count'); |
||
| 59 | $messageBox['Type'] = $folderID; |
||
| 60 | |||
| 61 | $page = $this->page; |
||
| 62 | |||
| 63 | if ($page > 0) { |
||
| 64 | $container = new self($this->folderID, $page - 1, $this->showAll); |
||
| 65 | $template->assign('PreviousPageHREF', $container->href()); |
||
| 66 | } |
||
| 67 | if (($page + 1) * MESSAGES_PER_PAGE < $messageBox['TotalMessages']) { |
||
| 68 | $container = new self($this->folderID, $page + 1, $this->showAll); |
||
| 69 | $template->assign('NextPageHREF', $container->href()); |
||
| 70 | } |
||
| 71 | |||
| 72 | $messageBox['Name'] = Messages::getMessageTypeNames($folderID); |
||
| 73 | $template->assign('PageTopic', 'Viewing ' . $messageBox['Name']); |
||
|
|
|||
| 74 | |||
| 75 | if ($messageBox['Type'] == MSG_GLOBAL || $messageBox['Type'] == MSG_SCOUT) { |
||
| 76 | $container = new MessagePreferenceProcessor($folderID); |
||
| 77 | $template->assign('PreferencesFormHREF', $container->href()); |
||
| 78 | } |
||
| 79 | |||
| 80 | $container = new MessageDeleteProcessor($folderID); |
||
| 81 | $messageBox['DeleteFormHref'] = $container->href(); |
||
| 82 | |||
| 83 | $dbResult = $db->read('SELECT * FROM message ' . |
||
| 84 | $whereClause . ' |
||
| 85 | ORDER BY send_time DESC |
||
| 86 | LIMIT ' . ($page * MESSAGES_PER_PAGE) . ', ' . MESSAGES_PER_PAGE); |
||
| 87 | |||
| 88 | $messageBox['NumberMessages'] = $dbResult->getNumRecords(); |
||
| 89 | $messageBox['Messages'] = []; |
||
| 90 | |||
| 91 | // Group scout messages if they wouldn't fit on a single page |
||
| 92 | if ($folderID == MSG_SCOUT && !$this->showAll && $messageBox['TotalMessages'] > $player->getScoutMessageGroupLimit()) { |
||
| 93 | // get rid of all old scout messages (>48h) |
||
| 94 | $db->write('DELETE FROM message WHERE expire_time < ' . $db->escapeNumber(Epoch::time()) . ' AND message_type_id = ' . $db->escapeNumber(MSG_SCOUT)); |
||
| 95 | |||
| 96 | $dispContainer = new self(MSG_SCOUT, showAll: true); |
||
| 97 | $messageBox['ShowAllHref'] = $dispContainer->href(); |
||
| 98 | |||
| 99 | displayScouts($messageBox, $player); |
||
| 100 | $template->unassign('NextPageHREF'); // always displaying all scout messages? |
||
| 101 | } else { |
||
| 102 | foreach ($dbResult->records() as $dbRecord) { |
||
| 103 | $messageBox['Messages'][] = displayMessage($dbRecord->getInt('message_id'), $dbRecord->getInt('account_id'), $dbRecord->getInt('sender_id'), $player->getGameID(), $dbRecord->getString('message_text'), $dbRecord->getInt('send_time'), $dbRecord->getBoolean('msg_read'), $folderID, $player->getAccount()); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | // This should really be part of a (pre)processing page |
||
| 108 | if ($page == 0 && !$session->ajax) { |
||
| 109 | $player->setMessagesRead($folderID); |
||
| 110 | } |
||
| 111 | |||
| 112 | $template->assign('MessageBox', $messageBox); |
||
| 113 | } |
||
| 226 |