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