| Conditions | 15 |
| Paths | 224 |
| Total Lines | 80 |
| Code Lines | 57 |
| Lines | 12 |
| Ratio | 15 % |
| 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 |
||
| 129 | function getKM() |
||
| 130 | { |
||
| 131 | $discord = $this->discord; |
||
| 132 | $this->newestKillmailID = getPermCache("newestKillmailID"); |
||
| 133 | $lastMail = $this->newestKillmailID; |
||
| 134 | View Code Duplication | if ($this->allianceID == "0" & $this->lossMail == 'true') { |
|
| 135 | $url = "https://zkillboard.com/api/no-attackers/no-items/orderDirection/asc/afterKillID/{$lastMail}/corporationID/{$this->corpID}/"; |
||
| 136 | } |
||
| 137 | View Code Duplication | if ($this->allianceID == "0" & $this->lossMail == 'false') { |
|
| 138 | $url = "https://zkillboard.com/api/no-attackers/no-items/kills/orderDirection/asc/afterKillID/{$lastMail}/corporationID/{$this->corpID}/"; |
||
| 139 | } |
||
| 140 | View Code Duplication | if ($this->allianceID != "0" & $this->lossMail == 'true') { |
|
| 141 | $url = "https://zkillboard.com/api/no-attackers/no-items/orderDirection/asc/afterKillID/{$lastMail}/allianceID/{$this->allianceID}/"; |
||
| 142 | } |
||
| 143 | View Code Duplication | if ($this->allianceID != "0" & $this->lossMail == 'false') { |
|
| 144 | $url = "https://zkillboard.com/api/no-attackers/no-items/kills/orderDirection/asc/afterKillID/{$lastMail}/allianceID/{$this->allianceID}/"; |
||
| 145 | } |
||
| 146 | |||
| 147 | if (!isset($url)) { // Make sure it's always set. |
||
| 148 | $this->logger->addInfo("ERROR - Ensure your config file is setup correctly for killmails."); |
||
| 149 | return null; |
||
| 150 | } |
||
| 151 | |||
| 152 | $xml = json_decode(downloadData($url), true); |
||
| 153 | $i = 0; |
||
| 154 | $limit = $this->spamAmount; |
||
| 155 | if (isset($xml)) { |
||
| 156 | foreach ($xml as $kill) { |
||
| 157 | if ($i < $limit) { |
||
| 158 | $killID = $kill['killID']; |
||
| 159 | if ($this->startMail > $killID) { |
||
| 160 | $killID = $this->startMail; |
||
| 161 | } |
||
| 162 | $solarSystemID = $kill['solarSystemID']; |
||
| 163 | $systemName = apiCharacterName($solarSystemID); |
||
| 164 | $killTime = $kill['killTime']; |
||
| 165 | $victimAllianceName = $kill['victim']['allianceName']; |
||
| 166 | $victimName = $kill['victim']['characterName']; |
||
| 167 | $victimCorpName = $kill['victim']['corporationName']; |
||
| 168 | $victimShipID = $kill['victim']['shipTypeID']; |
||
| 169 | $shipName = apiTypeName($victimShipID); |
||
| 170 | $rawValue = $kill['zkb']['totalValue']; |
||
| 171 | $totalValue = number_format($kill['zkb']['totalValue']); |
||
| 172 | //$iskValue = number_format(($totalValue/100), 0); |
||
| 173 | // Check if it's a structure |
||
| 174 | if ($victimName != "") { |
||
| 175 | if ($rawValue >= $this->bigKill){ |
||
| 176 | $msg = "@here \n :warning:***Expensive Killmail***:warning: \n **{$killTime}**\n\n**{$shipName}** worth **{$totalValue} ISK** flown by **{$victimName}** of (***{$victimCorpName}|{$victimAllianceName}***) killed in {$systemName}\nhttps://zkillboard.com/kill/{$killID}/"; |
||
| 177 | } |
||
| 178 | elseif ($rawValue <= $this->bigKill) |
||
| 179 | { |
||
| 180 | $msg = "**{$killTime}**\n\n**{$shipName}** worth **{$totalValue} ISK** flown by **{$victimName}** of (***{$victimCorpName}|{$victimAllianceName}***) killed in {$systemName}\nhttps://zkillboard.com/kill/{$killID}/"; |
||
| 181 | } |
||
| 182 | } elseif ($victimName == "") { |
||
| 183 | $msg = "**{$killTime}**\n\n**{$shipName}** worth **{$totalValue} ISK** owned by (***{$victimCorpName}|{$victimAllianceName}***) killed in {$systemName}\nhttps://zkillboard.com/kill/{$killID}/"; |
||
| 184 | } |
||
| 185 | |||
| 186 | if (!isset($msg)) { // Make sure it's always set. |
||
| 187 | return null; |
||
| 188 | } |
||
| 189 | |||
| 190 | $channelID = $this->kmChannel; |
||
| 191 | $guild = $discord->guilds->get('id', $this->guild); |
||
| 192 | $channel = $guild->channels->get('id', $channelID); |
||
| 193 | $channel->sendMessage($msg, false); |
||
| 194 | setPermCache("newestKillmailID", $killID); |
||
| 195 | |||
| 196 | sleep(2); |
||
| 197 | $i++; |
||
| 198 | } else { |
||
| 199 | $updatedID = getPermCache("newestKillmailID"); |
||
| 200 | $this->logger->addInfo("Kill posting cap reached, newest kill id is {$updatedID}"); |
||
| 201 | return null; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | } |
||
| 205 | $updatedID = getPermCache("newestKillmailID"); |
||
| 206 | $this->logger->addInfo("All kills posted, newest kill id is {$updatedID}"); |
||
| 207 | return null; |
||
| 208 | } |
||
| 209 | } |
||
| 210 |
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.