| Conditions | 12 |
| Paths | 58 |
| Total Lines | 87 |
| Code Lines | 53 |
| Lines | 6 |
| Ratio | 6.9 % |
| 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 |
||
| 104 | private function checkMails($keyID, $vCode, $characterID) |
||
| 105 | { |
||
| 106 | |||
| 107 | $url = "https://api.eveonline.com/char/MailMessages.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}"; |
||
| 108 | $data = json_decode(json_encode(simplexml_load_string(downloadData($url), 'SimpleXMLElement', LIBXML_NOCDATA)), true); |
||
| 109 | $xml = makeApiRequest($url); |
||
| 110 | $cached = $xml->cachedUntil[0]; |
||
| 111 | $baseUnix = strtotime($cached); |
||
| 112 | $cacheClr = $baseUnix - 13500; |
||
| 113 | |||
| 114 | //Set timer for next key based on number of keys |
||
| 115 | $nextKey = (1900 / (int)$this->numberOfKeys) + time(); |
||
| 116 | $nextKeyTime = gmdate('Y-m-d H:i:s', $nextKey); |
||
| 117 | setPermCache('mailLastChecked', $nextKey); |
||
| 118 | |||
| 119 | //Set cache timer for api key |
||
| 120 | View Code Duplication | if ($cacheClr <= time()) { |
|
| 121 | $weirdTime = time() + 1830; |
||
| 122 | setPermCache("mailLastChecked{$keyID}", $weirdTime); |
||
| 123 | } else { |
||
| 124 | setPermCache("mailLastChecked{$keyID}", $cacheClr); |
||
| 125 | } |
||
| 126 | |||
| 127 | // If there is no data, just quit.. |
||
| 128 | if (empty($data['result']['rowset']['row'])) { |
||
| 129 | return null; |
||
| 130 | } |
||
| 131 | $data = $data['result']['rowset']['row']; |
||
| 132 | |||
| 133 | $mails = array(); |
||
| 134 | if (isset($data['@attributes'])) { |
||
| 135 | $mails[] = $data['@attributes']; |
||
| 136 | } |
||
| 137 | // Sometimes there is only ONE notification, so.. yeah.. |
||
| 138 | if (count($data) > 1) { |
||
| 139 | foreach ($data as $multiMail) { |
||
| 140 | $mails[] = $multiMail['@attributes']; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | usort($mails, array($this, 'sortByDate')); |
||
| 145 | |||
| 146 | foreach ($mails as $mail) { |
||
| 147 | if (in_array($mail['toCorpOrAllianceID'], $this->toIDs) && $mail['messageID'] > $this->newestMailID) { |
||
| 148 | $sentBy = $mail['senderName']; |
||
| 149 | $title = $mail['title']; |
||
| 150 | $sentDate = $mail['sentDate']; |
||
| 151 | $url = "https://api.eveonline.com/char/MailBodies.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}&ids=" . $mail['messageID']; |
||
| 152 | $content = strip_tags(str_replace('<br>', "\n", json_decode(json_encode(simplexml_load_string(downloadData($url), 'SimpleXMLElement', LIBXML_NOCDATA)))->result->rowset->row)); |
||
| 153 | |||
| 154 | // Blank Content Check |
||
| 155 | if ($content === '') { |
||
| 156 | return null; |
||
| 157 | } |
||
| 158 | |||
| 159 | $messageSplit = str_split($content, 1850); |
||
| 160 | |||
| 161 | // Stitch the mail together |
||
| 162 | $msg = "**------------------------------------**\n"; |
||
| 163 | $msg .= "**Mail By: **{$sentBy}\n"; |
||
| 164 | $msg .= "**Sent Date: **{$sentDate}\n"; |
||
| 165 | $msg .= "**Title: ** {$title}\n"; |
||
| 166 | $msg .= "**Content: **\n"; |
||
| 167 | $msg .= htmlspecialchars_decode(trim($messageSplit[0]), null); |
||
| 168 | $msgLong = htmlspecialchars_decode(trim($messageSplit[1]), null); |
||
| 169 | |||
| 170 | // Send the mails to the channel |
||
| 171 | $channelID = $this->toDiscordChannel; |
||
| 172 | queueMessage($msg, $channelID, $this->guild); |
||
| 173 | $this->logger->addInfo('Mails: New mail queued'); |
||
| 174 | if (strlen($content) > 1850) { |
||
| 175 | queueMessage($msgLong, $channelID, $this->guild); |
||
| 176 | } |
||
| 177 | |||
| 178 | // Find the maxID so we don't spit this message out ever again |
||
| 179 | $this->maxID = max($mail['messageID'], $this->maxID); |
||
| 180 | $this->newestMailID = $this->maxID; //$mail["messageID"]; |
||
| 181 | $updateMaxID = true; |
||
| 182 | |||
| 183 | // set the maxID |
||
| 184 | if ($updateMaxID) { |
||
| 185 | setPermCache('newestCorpMailID', $this->maxID); |
||
| 186 | } |
||
| 187 | } |
||
| 188 | } |
||
| 189 | $this->logger->addInfo("Mails: Next Mail Check At: {$nextKeyTime} EVE Time"); |
||
| 190 | } |
||
| 191 | |||
| 202 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.