| Conditions | 15 |
| Paths | 76 |
| Total Lines | 82 |
| Code Lines | 59 |
| Lines | 65 |
| Ratio | 79.27 % |
| 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 |
||
| 90 | function checkTowers($keyID, $vCode) |
||
| 91 | { |
||
| 92 | $discord = $this->discord; |
||
| 93 | |||
| 94 | $url = "https://api.eveonline.com/corp/AssetList.xml.aspx?keyID={$keyID}&vCode={$vCode}"; |
||
| 95 | $xml = makeApiRequest($url); |
||
| 96 | $siphonCount = 0; |
||
| 97 | $rawGoo = array(16634, 16643, 16647, 16641, 16640, 16635, 16648, 16633, 16646, 16651, 16650, 16644, 16652, 16639, 16636, 16649, 16653, 16638, 16637, 16642); |
||
| 98 | foreach ($xml->result->rowset->row as $structures) { |
||
| 99 | //Check silos |
||
| 100 | View Code Duplication | if ($structures->attributes()->typeID == 14343) { |
|
| 101 | if (isset($structures->rowset->row)) { |
||
| 102 | foreach ($structures->rowset->row as $silo) { |
||
| 103 | //Avoid reporting empty silos |
||
| 104 | if ($silo->attributes()->quantity != 0 && in_array($silo->attributes()->typeID, $rawGoo)) { |
||
| 105 | //Check for a multiple of 50 |
||
| 106 | if ($silo->attributes()->quantity % 50 != 0) { |
||
| 107 | $gooType = apiTypeName($silo->attributes()->typeID); |
||
| 108 | $systemName = apiCharacterName($structures->attributes()->locationID); |
||
| 109 | $msg = "{$this->prefix}"; |
||
| 110 | $msg .= "**POSSIBLE SIPHON**\n"; |
||
| 111 | $msg .= "**System: **{$systemName} has a possible siphon stealing {$gooType} from a silo.\n"; |
||
| 112 | // Send the msg to the channel; |
||
| 113 | $channelID = $this->toDiscordChannel; |
||
| 114 | $guild = $discord->guilds->get('id', $this->guild); |
||
| 115 | $channel = $guild->channels->get('id', $channelID); |
||
| 116 | $channel->sendMessage($msg, false); |
||
| 117 | $this->logger->addInfo($msg); |
||
| 118 | $siphonCount++; |
||
| 119 | sleep(2); // Lets sleep for a second, so we don't rage spam |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | View Code Duplication | if ($structures->attributes()->typeID == 17982) { |
|
| 126 | if (isset($structures->rowset->row)) { |
||
| 127 | foreach ($structures->rowset->row as $coupling) { |
||
| 128 | //Avoid reporting empty coupling arrays |
||
| 129 | if ($coupling->attributes()->quantity != 0) { |
||
| 130 | //Check for a multiple of 50 |
||
| 131 | if ($coupling->attributes()->quantity % 50 != 0) { |
||
| 132 | $gooType = apiTypeName($silo->attributes()->typeID); |
||
| 133 | $systemName = apiCharacterName($structures->attributes()->locationID); |
||
| 134 | $msg = "{$this->prefix}"; |
||
| 135 | $msg .= "**POSSIBLE SIPHON**\n"; |
||
| 136 | $msg .= "**System: **{$systemName} has a possible siphon stealing {$gooType} from a coupling array.\n"; |
||
| 137 | // Send the msg to the channel; |
||
| 138 | $channelID = $this->toDiscordChannel; |
||
| 139 | $guild = $discord->guilds->get('id', $this->guild); |
||
| 140 | $channel = $guild->channels->get('id', $channelID); |
||
| 141 | $channel->sendMessage($msg, false); |
||
| 142 | $this->logger->addInfo($msg); |
||
| 143 | $siphonCount++; |
||
| 144 | sleep(2); // Lets sleep for a second, so we don't rage spam |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | $cached = $xml->cachedUntil[0]; |
||
| 152 | $baseUnix = strtotime($cached); |
||
| 153 | $cacheClr = $baseUnix - 13500; |
||
| 154 | View Code Duplication | if ($cacheClr <= time()) { |
|
| 155 | $weirdTime = time() + 21700; |
||
| 156 | $cacheTimer = gmdate("Y-m-d H:i:s", $weirdTime); |
||
| 157 | setPermCache("siphonLastChecked{$keyID}", $weirdTime); |
||
| 158 | } else { |
||
| 159 | $cacheTimer = gmdate("Y-m-d H:i:s", $cacheClr); |
||
| 160 | setPermCache("siphonLastChecked{$keyID}", $cacheClr); |
||
| 161 | } |
||
| 162 | View Code Duplication | if ($siphonCount > 0) { |
|
| 163 | $msg = "Next Siphon Check At: {$cacheTimer} EVE Time"; |
||
| 164 | $channelID = $this->toDiscordChannel; |
||
| 165 | $guild = $discord->guilds->get('id', $this->guild); |
||
| 166 | $channel = $guild->channels->get('id', $channelID); |
||
| 167 | $channel->sendMessage($msg, false); |
||
| 168 | } |
||
| 169 | $this->logger->addInfo("Siphon Check Complete Next Check At {$cacheTimer}"); |
||
| 170 | return null; |
||
| 171 | } |
||
| 172 | |||
| 192 |
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.