| Conditions | 11 |
| Paths | 56 |
| Total Lines | 77 |
| Code Lines | 51 |
| Lines | 8 |
| Ratio | 10.39 % |
| Changes | 6 | ||
| Bugs | 1 | 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 |
||
| 119 | public function checkMails($keyID, $vCode, $characterID) |
||
| 120 | { |
||
| 121 | $updateMaxID = false; |
||
| 122 | $url = "https://api.eveonline.com/char/MailMessages.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}"; |
||
| 123 | $data = json_decode(json_encode(simplexml_load_string(downloadData($url), 'SimpleXMLElement', LIBXML_NOCDATA)), true); |
||
| 124 | $data = $data['result']['rowset']['row']; |
||
| 125 | $xml = makeApiRequest($url); |
||
| 126 | $cached = $xml->cachedUntil[0]; |
||
| 127 | $baseUnix = strtotime($cached); |
||
| 128 | $cacheClr = $baseUnix - 13500; |
||
| 129 | View Code Duplication | if ($cacheClr <= time()) { |
|
| 130 | $weirdTime = time() + 1830; |
||
| 131 | $cacheTimer = gmdate('Y-m-d H:i:s', $weirdTime); |
||
| 132 | setPermCache("mailLastChecked{$keyID}", $weirdTime); |
||
| 133 | } else { |
||
| 134 | $cacheTimer = gmdate('Y-m-d H:i:s', $cacheClr); |
||
| 135 | setPermCache("mailLastChecked{$keyID}", $cacheClr); |
||
| 136 | } |
||
| 137 | |||
| 138 | $mails = []; |
||
| 139 | if (isset($data['@attributes'])) { |
||
| 140 | $mails[] = $data['@attributes']; |
||
| 141 | } |
||
| 142 | // Sometimes there is only ONE notification, so.. yeah.. |
||
| 143 | if (count($data) > 1) { |
||
| 144 | foreach ($data as $multiMail) { |
||
| 145 | $mails[] = $multiMail['@attributes']; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | usort($mails, [$this, 'sortByDate']); |
||
| 150 | |||
| 151 | foreach ($mails as $mail) { |
||
| 152 | if (in_array($mail['toCorpOrAllianceID'], $this->toIDs) && $mail['messageID'] > $this->newestMailID) { |
||
| 153 | $sentBy = $mail['senderName']; |
||
| 154 | $title = $mail['title']; |
||
| 155 | $sentDate = $mail['sentDate']; |
||
| 156 | $url = "https://api.eveonline.com/char/MailBodies.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}&ids=".$mail['messageID']; |
||
| 157 | $content = strip_tags(str_replace('<br>', "\n", json_decode(json_encode(simplexml_load_string(downloadData($url), 'SimpleXMLElement', LIBXML_NOCDATA)))->result->rowset->row)); |
||
| 158 | |||
| 159 | // Blank Content Check |
||
| 160 | if ($content == '') { |
||
| 161 | return; |
||
| 162 | } |
||
| 163 | |||
| 164 | $messageSplit = str_split($content, 1850); |
||
| 165 | |||
| 166 | // Stitch the mail together |
||
| 167 | $msg = "**Mail By: **{$sentBy}\n"; |
||
| 168 | $msg .= "**Sent Date: **{$sentDate}\n"; |
||
| 169 | $msg .= "**Title: ** {$title}\n"; |
||
| 170 | $msg .= "**Content: **\n"; |
||
| 171 | $msg .= htmlspecialchars_decode(trim($messageSplit[0])); |
||
| 172 | $msgLong = htmlspecialchars_decode(trim($messageSplit[1])); |
||
| 173 | |||
| 174 | // Send the mails to the channel |
||
| 175 | $channelID = $this->toDiscordChannel; |
||
| 176 | $channel = Channel::find($channelID); |
||
| 177 | $channel->sendMessage($msg, false); |
||
| 178 | sleep(1); // Lets sleep for a second, so we don't rage spam |
||
| 179 | if (strlen($content) > 1850) { |
||
| 180 | $channel->sendMessage($msgLong, false); |
||
| 181 | } |
||
| 182 | |||
| 183 | // Find the maxID so we don't spit this message out ever again |
||
| 184 | $this->maxID = max($mail['messageID'], $this->maxID); |
||
| 185 | $this->newestMailID = $this->maxID; //$mail["messageID"]; |
||
| 186 | $updateMaxID = true; |
||
| 187 | |||
| 188 | // set the maxID |
||
| 189 | if ($updateMaxID) { |
||
| 190 | setPermCache('newestCorpMailID', $this->maxID); |
||
| 191 | } |
||
| 192 | } |
||
| 193 | } |
||
| 194 | $this->logger->addInfo("Next Mail Check At: {$cacheTimer} EVE Time"); |
||
| 195 | } |
||
| 196 | |||
| 225 |
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.