| Conditions | 21 |
| Paths | 46 |
| Total Lines | 92 |
| Code Lines | 64 |
| Lines | 72 |
| Ratio | 78.26 % |
| 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 |
||
| 97 | function checkTowers() |
||
| 98 | { |
||
| 99 | foreach($this->groupConfig as $siphonCorp) { |
||
| 100 | //If group channel is set to 0 skip |
||
| 101 | if($siphonCorp["channelID"] == 0){ |
||
| 102 | continue; |
||
| 103 | } |
||
| 104 | $url = "https://api.eveonline.com/corp/AssetList.xml.aspx?keyID={$siphonCorp["keyID"]}&vCode={$siphonCorp["vCode"]}"; |
||
| 105 | $xml = makeApiRequest($url); |
||
| 106 | $rawGoo = array(16634, 16643, 16647, 16641, 16640, 16635, 16648, 16633, 16646, 16651, 16650, 16644, 16652, 16639, 16636, 16649, 16653, 16638, 16637, 16642); |
||
| 107 | foreach ($xml->result->rowset->row as $structures) { |
||
| 108 | //Check silos |
||
| 109 | View Code Duplication | if ($structures->attributes()->typeID == 14343) { |
|
| 110 | if (isset($structures->rowset->row)) { |
||
| 111 | foreach ($structures->rowset->row as $silo) { |
||
| 112 | //Avoid reporting empty silos |
||
| 113 | if ($silo->attributes()->quantity != 0 && in_array($silo->attributes()->typeID, $rawGoo)) { |
||
| 114 | $siloID = $structures->attributes()->itemID; |
||
| 115 | $lastAmount = getPermCache("silo{$siloID}Amount"); |
||
| 116 | $gooAmount = $silo->attributes()->quantity; |
||
| 117 | $gooDifference = $gooAmount - $lastAmount; |
||
| 118 | //Check if silo has been checked before |
||
| 119 | if(!isset($lastAmount) || $gooDifference < 0){ |
||
| 120 | setPermCache("silo{$siloID}Amount", $gooAmount); |
||
| 121 | continue; |
||
| 122 | } |
||
| 123 | //Check for a multiple of 50 in the difference |
||
| 124 | if ($gooDifference % 50 != 0) { |
||
| 125 | $gooType = apiTypeName($silo->attributes()->typeID); |
||
| 126 | $systemName = apiCharacterName($structures->attributes()->locationID); |
||
| 127 | $msg = "{$siphonCorp["prefix"]}"; |
||
| 128 | $msg .= "**POSSIBLE SIPHON**\n"; |
||
| 129 | $msg .= "**System: **{$systemName} has a possible siphon stealing {$gooType} from a silo.\n"; |
||
| 130 | // Queue the message |
||
| 131 | priorityQueueMessage($msg, $siphonCorp["channelID"], $this->guild); |
||
| 132 | $this->logger->addInfo("Siphons: {$msg}"); |
||
| 133 | setPermCache("silo{$siloID}Amount", $gooAmount); |
||
| 134 | } else { |
||
| 135 | setPermCache("silo{$siloID}Amount", $gooAmount); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | } |
||
| 141 | View Code Duplication | if ($structures->attributes()->typeID == 17982) { |
|
| 142 | if (isset($structures->rowset->row)) { |
||
| 143 | foreach ($structures->rowset->row as $coupling) { |
||
| 144 | //Avoid reporting empty coupling arrays |
||
| 145 | if ($coupling->attributes()->quantity != 0 && in_array($coupling->attributes()->typeID, $rawGoo)) { |
||
| 146 | $couplingID = $structures->attributes()->itemID; |
||
| 147 | $lastAmount = getPermCache("couplingArray{$couplingID}Amount"); |
||
| 148 | $gooAmount = $coupling->attributes()->quantity; |
||
| 149 | $gooDifference = $gooAmount - $lastAmount; |
||
| 150 | //Check if silo has been checked before |
||
| 151 | if(!isset($lastAmount) || $gooDifference < 0){ |
||
| 152 | setPermCache("couplingArray{$couplingID}Amount", $gooAmount); |
||
| 153 | continue; |
||
| 154 | } |
||
| 155 | //Check for a multiple of 50 in the difference |
||
| 156 | if ($gooDifference % 50 != 0) { |
||
| 157 | $gooType = apiTypeName($coupling->attributes()->typeID); |
||
| 158 | $systemName = apiCharacterName($structures->attributes()->locationID); |
||
| 159 | $msg = "{$siphonCorp["prefix"]}"; |
||
| 160 | $msg .= "**POSSIBLE SIPHON**\n"; |
||
| 161 | $msg .= "**System: **{$systemName} has a possible siphon stealing {$gooType} from a coupling array.\n"; |
||
| 162 | // Queue the message |
||
| 163 | priorityQueueMessage($msg, $siphonCorp["channelID"], $this->guild); |
||
| 164 | $this->logger->addInfo("Siphons: {$msg}"); |
||
| 165 | setPermCache("couplingArray{$couplingID}Amount", $gooAmount); |
||
| 166 | } else { |
||
| 167 | setPermCache("couplingArray{$couplingID}Amount", $gooAmount); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 | } |
||
| 174 | $cached = $xml->cachedUntil[0]; |
||
| 175 | $baseUnix = strtotime($cached); |
||
| 176 | $cacheClr = $baseUnix - 13500; |
||
| 177 | View Code Duplication | if ($cacheClr <= time()) { |
|
| 178 | $weirdTime = time() + 21700; |
||
| 179 | $cacheTimer = gmdate("Y-m-d H:i:s", $weirdTime); |
||
| 180 | setPermCache("siphonLastChecked{$siphonCorp["keyID"]}", $weirdTime); |
||
| 181 | } else { |
||
| 182 | $cacheTimer = gmdate("Y-m-d H:i:s", $cacheClr); |
||
| 183 | setPermCache("siphonLastChecked{$siphonCorp["keyID"]}", $cacheClr); |
||
| 184 | } |
||
| 185 | $this->logger->addInfo("Siphons: Siphon Check Complete Next Check At {$cacheTimer}"); |
||
| 186 | return null; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | } |
||
| 190 |
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.