| Conditions | 32 |
| Paths | 4097 |
| Total Lines | 107 |
| Code Lines | 67 |
| Lines | 25 |
| Ratio | 23.36 % |
| 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 |
||
| 84 | private function getKM() |
||
| 85 | { |
||
| 86 | foreach ($this->groupConfig as $kmGroup) { |
||
| 87 | $SavedKillID = getPermCache("{$kmGroup['name']}newestKillmailID"); |
||
| 88 | //check if start id is greater than current id and if it is set |
||
| 89 | if (null !== $SavedKillID && preg_match('/[a-z]/i', $SavedKillID)) { |
||
| 90 | getStartMail($kmGroup); |
||
| 91 | $SavedKillID = getPermCache("{$kmGroup['name']}newestKillmailID"); |
||
| 92 | } |
||
| 93 | if ($kmGroup['startMail'] > $SavedKillID || null === $SavedKillID) { |
||
| 94 | $SavedKillID = $kmGroup['startMail']; |
||
| 95 | } |
||
| 96 | View Code Duplication | if ((string)$kmGroup['allianceID'] === '0' & $kmGroup['lossMails'] === 'true') { |
|
| 97 | $url = "https://zkillboard.com/api/corporationID/{$kmGroup['corpID']}/no-attackers/no-items/orderDirection/asc/pastSeconds/10800/"; |
||
| 98 | } |
||
| 99 | View Code Duplication | if ((string)$kmGroup['allianceID'] === '0' & $kmGroup['lossMails'] === 'false') { |
|
| 100 | $url = "https://zkillboard.com/api/corporationID/{$kmGroup['corpID']}/no-attackers/no-items/kills/orderDirection/asc/pastSeconds/10800/"; |
||
| 101 | } |
||
| 102 | View Code Duplication | if ((string)$kmGroup['allianceID'] !== '0' & $kmGroup['lossMails'] === 'true') { |
|
| 103 | $url = "https://zkillboard.com/api/allianceID/{$kmGroup['allianceID']}/no-attackers/no-items/orderDirection/asc/pastSeconds/10800/"; |
||
| 104 | } |
||
| 105 | View Code Duplication | if ((string)$kmGroup['allianceID'] !== '0' & $kmGroup['lossMails'] === 'false') { |
|
| 106 | $url = "https://zkillboard.com/api/allianceID/{$kmGroup['allianceID']}/no-attackers/no-items/kills/orderDirection/asc/pastSeconds/10800/"; |
||
| 107 | } |
||
| 108 | |||
| 109 | if (!isset($url)) { // Make sure it's always set. |
||
| 110 | $this->logger->addInfo('Killmails: ERROR - Ensure your config file is setup correctly for killmails.'); |
||
| 111 | return null; |
||
| 112 | } |
||
| 113 | |||
| 114 | $kills = json_decode(downloadData($url), true); |
||
| 115 | // $i = 0; |
||
| 116 | if (isset($kills)) { |
||
| 117 | foreach ($kills as $kill) { |
||
| 118 | // if ($i < 10) { |
||
| 119 | //if big kill isn't set, disable it |
||
| 120 | if (!array_key_exists('bigKill', $kmGroup)) { |
||
| 121 | $kmGroup['bigKill'] = 99999999999999999999999999; |
||
| 122 | } |
||
| 123 | $killID = $kill['killID']; |
||
| 124 | if ($killID <= $SavedKillID) { |
||
| 125 | // $i++; |
||
| 126 | continue; |
||
| 127 | } |
||
| 128 | $channelID = $kmGroup['channel']; |
||
| 129 | $solarSystemID = $kill['solarSystemID']; |
||
| 130 | $systemName = systemName($solarSystemID); |
||
| 131 | $killTime = $kill['killTime']; |
||
| 132 | $victimAllianceName = ''; |
||
| 133 | View Code Duplication | if ($kill['victim']['allianceName'] !== null && $kill['victim']['allianceName'] !== '') { |
|
| 134 | $victimAllianceName = "|{$kill['victim']['allianceName']}"; |
||
| 135 | } |
||
| 136 | $victimName = $kill['victim']['characterName']; |
||
| 137 | $victimCorpName = $kill['victim']['corporationName']; |
||
| 138 | $victimShipID = $kill['victim']['shipTypeID']; |
||
| 139 | $shipName = apiTypeName($victimShipID); |
||
| 140 | $rawValue = $kill['zkb']['totalValue']; |
||
| 141 | //Check if killmail meets minimum value and if it meets lost minimum value |
||
| 142 | if (isset($kmGroup['minimumValue']) && isset($kmGroup['minimumlossValue'])) { |
||
| 143 | if ($rawValue < $kmGroup['minimumValue']) { |
||
| 144 | if ($kill['victim']['corporationID'] == $kmGroup['corpID'] && $rawValue > $kmGroup['minimumlossValue'] || |
||
| 145 | $kill['victim']['allianceID'] == $kmGroup['allianceID'] && $rawValue > $kmGroup['minimumlossValue']) |
||
| 146 | { |
||
| 147 | $this->logger->addInfo("Killmails: Mail {$killID} posted because it meet minimum loss value required."); |
||
| 148 | } else { |
||
| 149 | $this->logger->addInfo("Killmails: Mail {$killID} ignored for not meeting the minimum value required."); |
||
| 150 | setPermCache("{$kmGroup['name']}newestKillmailID", $killID); |
||
| 151 | continue; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | } |
||
| 155 | $totalValue = number_format($kill['zkb']['totalValue']); |
||
| 156 | // Check if it's a structure |
||
| 157 | View Code Duplication | if ($victimName !== '') { |
|
| 158 | if ($kmGroup['bigKill'] != null && $rawValue >= $kmGroup['bigKill']) { |
||
| 159 | $channelID = $kmGroup['bigKillChannel']; |
||
| 160 | $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}/"; |
||
| 161 | } elseif ($kmGroup['bigKill'] == null || $rawValue <= $kmGroup['bigKill']) { |
||
| 162 | $msg = "**{$killTime}**\n\n**{$shipName}** worth **{$totalValue} ISK** flown by **{$victimName}** of (***{$victimCorpName}|{$victimAllianceName}***) killed in {$systemName}\nhttps://zkillboard.com/kill/{$killID}/"; |
||
| 163 | } |
||
| 164 | } elseif ($victimName === '') { |
||
| 165 | $msg = "**{$killTime}**\n\n**{$shipName}** worth **{$totalValue} ISK** owned by (***{$victimCorpName}|{$victimAllianceName}***) killed in {$systemName}\nhttps://zkillboard.com/kill/{$killID}/"; |
||
| 166 | } |
||
| 167 | |||
| 168 | if (!isset($msg)) { // Make sure it's always set. |
||
| 169 | return null; |
||
| 170 | } |
||
| 171 | queueMessage($msg, $channelID, $this->guild); |
||
| 172 | $this->logger->addInfo("Killmails: Mail {$killID} queued."); |
||
| 173 | |||
| 174 | // $i++; |
||
| 175 | /* } else { |
||
| 176 | $updatedID = getPermCache("{$kmGroup['name']}newestKillmailID"); |
||
| 177 | $this->logger->addInfo("Killmails: Kill posting cap reached, newest kill id for {$kmGroup['name']} is {$updatedID}"); |
||
| 178 | break; |
||
| 179 | }*/ |
||
| 180 | } |
||
| 181 | if (!isset($killID)) { |
||
| 182 | $killID = $SavedKillID; |
||
| 183 | } |
||
| 184 | setPermCache("{$kmGroup['name']}newestKillmailID", $killID); |
||
| 185 | } |
||
| 186 | $updatedID = getPermCache("{$kmGroup['name']}newestKillmailID"); |
||
| 187 | $this->logger->addInfo("Killmails: All kills posted, newest kill id for {$kmGroup['name']} is {$updatedID}"); |
||
| 188 | continue; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 254 |
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.