| Conditions | 14 |
| Paths | 76 |
| Total Lines | 81 |
| Code Lines | 58 |
| Lines | 65 |
| Ratio | 80.25 % |
| 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 | foreach ($xml->result->rowset->row as $structures) { |
||
| 98 | //Check silos |
||
| 99 | View Code Duplication | if ($structures->attributes()->typeID == 14343) { |
|
| 100 | if (isset($structures->rowset->row)) { |
||
| 101 | foreach ($structures->rowset->row as $silo) { |
||
| 102 | //Avoid reporting empty silos |
||
| 103 | if ($silo->attributes()->quantity != 0) { |
||
| 104 | //Check for a multiple of 50 |
||
| 105 | if ($silo->attributes()->quantity % 50 != 0) { |
||
| 106 | $gooType = apiTypeName($silo->attributes()->typeID); |
||
| 107 | $systemName = apiCharacterName($structures->attributes()->locationID); |
||
| 108 | $msg = "{$this->prefix}"; |
||
| 109 | $msg .= "**POSSIBLE SIPHON**\n"; |
||
| 110 | $msg .= "**System: **{$systemName} has a possible siphon stealing {$gooType} from a silo.\n"; |
||
| 111 | // Send the msg to the channel; |
||
| 112 | $channelID = $this->toDiscordChannel; |
||
| 113 | $guild = $discord->guilds->get('id', $this->guild); |
||
| 114 | $channel = $guild->channels->get('id', $channelID); |
||
| 115 | $channel->sendMessage($msg, false); |
||
| 116 | $this->logger->addInfo($msg); |
||
| 117 | $siphonCount++; |
||
| 118 | sleep(2); // Lets sleep for a second, so we don't rage spam |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | View Code Duplication | if ($structures->attributes()->typeID == 17982) { |
|
| 125 | if (isset($structures->rowset->row)) { |
||
| 126 | foreach ($structures->rowset->row as $coupling) { |
||
| 127 | //Avoid reporting empty coupling arrays |
||
| 128 | if ($coupling->attributes()->quantity != 0) { |
||
| 129 | //Check for a multiple of 50 |
||
| 130 | if ($coupling->attributes()->quantity % 50 != 0) { |
||
| 131 | $gooType = apiTypeName($silo->attributes()->typeID); |
||
|
1 ignored issue
–
show
|
|||
| 132 | $systemName = apiCharacterName($structures->attributes()->locationID); |
||
| 133 | $msg = "{$this->prefix}"; |
||
| 134 | $msg .= "**POSSIBLE SIPHON**\n"; |
||
| 135 | $msg .= "**System: **{$systemName} has a possible siphon stealing {$gooType} from a coupling array.\n"; |
||
| 136 | // Send the msg to the channel; |
||
| 137 | $channelID = $this->toDiscordChannel; |
||
| 138 | $guild = $discord->guilds->get('id', $this->guild); |
||
| 139 | $channel = $guild->channels->get('id', $channelID); |
||
| 140 | $channel->sendMessage($msg, false); |
||
| 141 | $this->logger->addInfo($msg); |
||
| 142 | $siphonCount++; |
||
| 143 | sleep(2); // Lets sleep for a second, so we don't rage spam |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | $cached = $xml->cachedUntil[0]; |
||
| 151 | $baseUnix = strtotime($cached); |
||
| 152 | $cacheClr = $baseUnix - 13500; |
||
| 153 | View Code Duplication | if ($cacheClr <= time()) { |
|
| 154 | $weirdTime = time() + 21700; |
||
| 155 | $cacheTimer = gmdate("Y-m-d H:i:s", $weirdTime); |
||
| 156 | setPermCache("siphonLastChecked{$keyID}", $weirdTime); |
||
| 157 | } else { |
||
| 158 | $cacheTimer = gmdate("Y-m-d H:i:s", $cacheClr); |
||
| 159 | setPermCache("siphonLastChecked{$keyID}", $cacheClr); |
||
| 160 | } |
||
| 161 | View Code Duplication | if ($siphonCount > 0) { |
|
| 162 | $msg = "Next Siphon Check At: {$cacheTimer} EVE Time"; |
||
| 163 | $channelID = $this->toDiscordChannel; |
||
| 164 | $guild = $discord->guilds->get('id', $this->guild); |
||
| 165 | $channel = $guild->channels->get('id', $channelID); |
||
| 166 | $channel->sendMessage($msg, false); |
||
| 167 | } |
||
| 168 | $this->logger->addInfo("Siphon Check Complete Next Check At {$cacheTimer}"); |
||
| 169 | return null; |
||
| 170 | } |
||
| 171 | |||
| 191 |
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.