| Conditions | 49 |
| Paths | 10230 |
| Total Lines | 304 |
| Code Lines | 286 |
| Lines | 82 |
| Ratio | 26.97 % |
| Changes | 5 | ||
| Bugs | 2 | Features | 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 |
||
| 134 | public function getNotifications($keyID, $vCode, $characterID) |
||
| 135 | { |
||
| 136 | try { |
||
| 137 | $url = "https://api.eveonline.com/char/Notifications.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}"; |
||
| 138 | $xml = makeApiRequest($url); |
||
| 139 | date_default_timezone_set('UTC'); |
||
| 140 | $cached = $xml->cachedUntil[0]; |
||
| 141 | $baseUnix = strtotime($cached); |
||
| 142 | $cacheClr = $baseUnix - 13500; |
||
| 143 | View Code Duplication | if ($cacheClr <= time()) { |
|
| 144 | $weirdTime = time() + 1830; |
||
| 145 | $cacheTimer = gmdate('Y-m-d H:i:s', $weirdTime); |
||
| 146 | setPermCache("notificationsLastChecked{$keyID}", $weirdTime); |
||
| 147 | } else { |
||
| 148 | $cacheTimer = gmdate('Y-m-d H:i:s', $cacheClr); |
||
| 149 | setPermCache("notificationsLastChecked{$keyID}", $cacheClr); |
||
| 150 | } |
||
| 151 | $data = json_decode(json_encode(simplexml_load_string(downloadData($url), |
||
| 152 | 'SimpleXMLElement', LIBXML_NOCDATA)), true); |
||
| 153 | $data = $data['result']['rowset']['row']; |
||
| 154 | // If there is no data, just quit.. |
||
| 155 | if (empty($data)) { |
||
| 156 | return; |
||
| 157 | } |
||
| 158 | $fixedData = []; |
||
| 159 | // Sometimes there is only ONE notification, so.. yeah.. |
||
| 160 | if (isset($data['@attributes'])) { |
||
| 161 | $fixedData[] = $data['@attributes']; |
||
| 162 | } |
||
| 163 | if (count($data) > 1) { |
||
| 164 | foreach ($data as $multiNotif) { |
||
| 165 | $fixedData[] = $multiNotif['@attributes']; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | foreach ($fixedData as $notification) { |
||
| 169 | $notificationID = $notification['notificationID']; |
||
| 170 | $typeID = $notification['typeID']; |
||
| 171 | $sentDate = $notification['sentDate']; |
||
| 172 | if ($notificationID > $this->newestNotificationID) { |
||
| 173 | $notificationString = explode("\n", $this->getNotificationText($keyID, $vCode, $characterID, |
||
| 174 | $notificationID)); |
||
| 175 | switch ($typeID) { |
||
| 176 | case 5: // War Declared |
||
| 177 | $aggAllianceID = trim(explode(': ', $notificationString[2])[1]); |
||
| 178 | $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName']; |
||
| 179 | $delayHours = trim(explode(': ', $notificationString[3])[1]); |
||
| 180 | $msg = "@everyone | War declared by {$aggAllianceName}. Fighting begins in roughly {$delayHours} hours."; |
||
| 181 | break; |
||
| 182 | case 7: // War Declared corp |
||
| 183 | $aggCorpID = trim(explode(': ', $notificationString[2])[1]); |
||
| 184 | $aggCorpName = $this->apiData('corp', $aggCorpID)['corporationName']; |
||
| 185 | $msg = "@everyone | War declared by {$aggCorpName}. Fighting begins in roughly 24 hours."; |
||
| 186 | break; |
||
| 187 | case 8: // Alliance war invalidated by CONCORD |
||
| 188 | $aggAllianceID = trim(explode(': ', $notificationString[2])[1]); |
||
| 189 | $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName']; |
||
| 190 | $msg = "War declared by {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours."; |
||
| 191 | break; |
||
| 192 | case 10: // Bill issued |
||
| 193 | $msg = 'skip'; |
||
| 194 | break; |
||
| 195 | case 14: // Bounty payment |
||
| 196 | $msg = 'skip'; |
||
| 197 | break; |
||
| 198 | case 16: // Mail |
||
| 199 | $msg = 'skip'; |
||
| 200 | break; |
||
| 201 | case 19: // corp tax changed |
||
| 202 | $corpID = trim(explode(': ', $notificationString[0])[1]); |
||
| 203 | $corpName = $this->apiData('corp', $corpID)['corporationName']; |
||
| 204 | $oldTax = trim(explode(': ', $notificationString[2])[1]); |
||
| 205 | $newTax = trim(explode(': ', $notificationString[1])[1]); |
||
| 206 | $msg = "{$corpName} tax changed from {$oldTax}% to {$newTax}%"; |
||
| 207 | break; |
||
| 208 | case 21: // member left corp |
||
| 209 | $msg = 'skip'; |
||
| 210 | break; |
||
| 211 | case 35: // Insurance payment |
||
| 212 | $msg = 'skip'; |
||
| 213 | break; |
||
| 214 | View Code Duplication | case 41: // System lost |
|
| 215 | $systemID = trim(explode(': ', $notificationString[2])[1]); |
||
| 216 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 217 | 'solarSystemName', [':id' => $systemID], 'ccp'); |
||
| 218 | $allianceID = trim(explode(': ', $notificationString[0])[1]); |
||
| 219 | $allianceName = $this->apiData('alli', $allianceID)['allianceName']; |
||
| 220 | $msg = "{$allianceName} has lost control of **{$systemName}**"; |
||
| 221 | break; |
||
| 222 | View Code Duplication | case 43: // System captured |
|
| 223 | $systemID = trim(explode(': ', $notificationString[2])[1]); |
||
| 224 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 225 | 'solarSystemName', [':id' => $systemID], 'ccp'); |
||
| 226 | $allianceID = trim(explode(': ', $notificationString[0])[1]); |
||
| 227 | $allianceName = $this->apiData('alli', $allianceID)['allianceName']; |
||
| 228 | $msg = "{$allianceName} now controls **{$systemName}**"; |
||
| 229 | break; |
||
| 230 | case 52: // clone revoked |
||
| 231 | $msg = 'skip'; |
||
| 232 | break; |
||
| 233 | case 57: // jump clone destruction |
||
| 234 | $msg = 'skip'; |
||
| 235 | break; |
||
| 236 | case 71: // Mission Expiration |
||
| 237 | $msg = 'skip'; |
||
| 238 | break; |
||
| 239 | case 75: // POS / POS Module under attack |
||
| 240 | $aggAllianceID = trim(explode(': ', $notificationString[0])[1]); |
||
| 241 | $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName']; |
||
| 242 | $aggCorpID = trim(explode(': ', $notificationString[1])[1]); |
||
| 243 | $aggCorpName = $this->apiData('corp', $aggCorpID)['corporationName']; |
||
| 244 | $aggID = trim(explode(': ', $notificationString[2])[1]); |
||
| 245 | $aggCharacterName = $this->apiData('char', $aggID)['characterName']; |
||
| 246 | $armorValue = trim(explode(': ', $notificationString[3])[1]); |
||
| 247 | $hullValue = trim(explode(': ', $notificationString[4])[1]); |
||
| 248 | $moonID = trim(explode(': ', $notificationString[5])[1]); |
||
| 249 | $moonName = dbQueryField('SELECT itemName FROM mapAllCelestials WHERE itemID = :id', |
||
| 250 | 'itemName', [':id' => $moonID], 'ccp'); |
||
| 251 | $shieldValue = trim(explode(': ', $notificationString[6])[1]); |
||
| 252 | $solarSystemID = trim(explode(': ', $notificationString[7])[1]); |
||
| 253 | $typeID = trim(explode(': ', $notificationString[8])[1]); |
||
| 254 | $typeName = dbQueryField('SELECT typeName FROM invTypes WHERE typeID = :id', |
||
| 255 | 'typeName', [':id' => $typeID], 'ccp'); |
||
| 256 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 257 | 'solarSystemName', [':id' => $solarSystemID], 'ccp'); |
||
| 258 | $msg = "{$typeName} under attack in **{$systemName} - {$moonName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}"; |
||
| 259 | break; |
||
| 260 | case 76: // Tower resource alert |
||
| 261 | $moonID = trim(explode(': ', $notificationString[2])[1]); |
||
| 262 | $moonName = dbQueryField('SELECT itemName FROM mapAllCelestials WHERE itemID = :id', |
||
| 263 | 'itemName', [':id' => $moonID], 'ccp'); |
||
| 264 | $solarSystemID = trim(explode(': ', $notificationString[3])[1]); |
||
| 265 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 266 | 'solarSystemName', [':id' => $solarSystemID], 'ccp'); |
||
| 267 | $blocksRemaining = trim(explode(': ', $notificationString[6])[1]); |
||
| 268 | $typeID = trim(explode(': ', $notificationString[7])[1]); |
||
| 269 | $typeName = dbQueryField('SELECT typeName FROM invTypes WHERE typeID = :id', |
||
| 270 | 'typeName', [':id' => $typeID], 'ccp'); |
||
| 271 | $msg = "POS in {$systemName} - {$moonName} needs fuel. Only {$blocksRemaining} {$typeName}'s remaining."; |
||
| 272 | break; |
||
| 273 | case 88: // IHUB is being attacked |
||
| 274 | $aggAllianceID = trim(explode(': ', $notificationString[0])[1]); |
||
| 275 | $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName']; |
||
| 276 | $aggCorpID = trim(explode(': ', $notificationString[0])[1]); |
||
| 277 | $aggCorpName = $this->apiData('corp', $aggCorpID)['corporationName']; |
||
| 278 | $aggID = trim(explode(': ', $notificationString[1])[1]); |
||
| 279 | $aggCharacterName = $this->apiData('char', $aggID)['characterName']; |
||
| 280 | $armorValue = trim(explode(': ', $notificationString[3])[1]); |
||
| 281 | $hullValue = trim(explode(': ', $notificationString[4])[1]); |
||
| 282 | $shieldValue = trim(explode(': ', $notificationString[5])[1]); |
||
| 283 | $solarSystemID = trim(explode(': ', $notificationString[6])[1]); |
||
| 284 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 285 | 'solarSystemName', [':id' => $solarSystemID], 'ccp'); |
||
| 286 | $msg = "IHUB under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}"; |
||
| 287 | break; |
||
| 288 | case 93: // Customs office is being attacked |
||
| 289 | $aggAllianceID = trim(explode(': ', $notificationString[0])[1]); |
||
| 290 | $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName']; |
||
| 291 | $aggCorpID = trim(explode(': ', $notificationString[0])[1]); |
||
| 292 | $aggCorpName = $this->apiData('corp', $aggCorpID)['corporationName']; |
||
| 293 | $aggID = trim(explode(': ', $notificationString[2])[1]); |
||
| 294 | $aggCharacterName = $this->apiData('char', $aggID)['characterName']; |
||
| 295 | $planetID = trim(explode(': ', $notificationString[3])[1]); |
||
| 296 | $planetName = dbQueryField('SELECT itemName FROM mapAllCelestials WHERE itemID = :id', |
||
| 297 | 'itemName', [':id' => $planetID], 'ccp'); |
||
| 298 | $shieldValue = trim(explode(': ', $notificationString[5])[1]); |
||
| 299 | $solarSystemID = trim(explode(': ', $notificationString[6])[1]); |
||
| 300 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 301 | 'solarSystemName', [':id' => $solarSystemID], 'ccp'); |
||
| 302 | $msg = "Customs Office under attack in **{$systemName}** ($planetName) by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Shield Status: {$shieldValue}"; |
||
| 303 | break; |
||
| 304 | case 94: // POCO Reinforced |
||
| 305 | $msg = 'Customs Office reinforced.'; |
||
| 306 | break; |
||
| 307 | case 95: // IHub Transfer |
||
| 308 | $msg = 'skip'; |
||
| 309 | break; |
||
| 310 | case 103: // War support offer? I think? |
||
| 311 | $msg = 'skip'; |
||
| 312 | break; |
||
| 313 | case 111: // Bounty |
||
| 314 | $msg = 'skip'; |
||
| 315 | break; |
||
| 316 | case 128: // Corp App |
||
| 317 | $msg = 'skip'; |
||
| 318 | break; |
||
| 319 | case 130: // Corp app withdrawn? |
||
| 320 | $msg = 'skip'; |
||
| 321 | break; |
||
| 322 | case 138: // Clone activation |
||
| 323 | $msg = 'skip'; |
||
| 324 | break; |
||
| 325 | case 140: // Kill report |
||
| 326 | $msg = 'skip'; |
||
| 327 | break; |
||
| 328 | case 141: // Kill report |
||
| 329 | $msg = 'skip'; |
||
| 330 | break; |
||
| 331 | View Code Duplication | case 147: // Entosis has stated |
|
| 332 | $systemID = trim(explode(': ', $notificationString[0])[1]); |
||
| 333 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 334 | 'solarSystemName', [':id' => $systemID], 'ccp'); |
||
| 335 | $typeID = trim(explode(': ', $notificationString[1])[1]); |
||
| 336 | $typeName = dbQueryField('SELECT typeName FROM invTypes WHERE typeID = :id', |
||
| 337 | 'typeName', [':id' => $typeID], 'ccp'); |
||
| 338 | $msg = "@everyone | Entosis has started in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)"; |
||
| 339 | break; |
||
| 340 | View Code Duplication | case 148: // Entosis enabled a module ?????? |
|
|
1 ignored issue
–
show
|
|||
| 341 | $systemID = trim(explode(': ', $notificationString[0])[1]); |
||
| 342 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 343 | 'solarSystemName', [':id' => $systemID], 'ccp'); |
||
| 344 | $typeID = trim(explode(': ', $notificationString[1])[1]); |
||
| 345 | $typeName = dbQueryField('SELECT typeName FROM invTypes WHERE typeID = :id', |
||
| 346 | 'typeName', [':id' => $typeID], 'ccp'); |
||
| 347 | $msg = "Entosis has enabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)"; |
||
| 348 | break; |
||
| 349 | View Code Duplication | case 149: // Entosis disabled a module |
|
| 350 | $systemID = trim(explode(': ', $notificationString[0])[1]); |
||
| 351 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 352 | 'solarSystemName', [':id' => $systemID], 'ccp'); |
||
| 353 | $typeID = trim(explode(': ', $notificationString[1])[1]); |
||
| 354 | $typeName = dbQueryField('SELECT typeName FROM invTypes WHERE typeID = :id', |
||
| 355 | 'typeName', [':id' => $typeID], 'ccp'); |
||
| 356 | $msg = "Entosis has disabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)"; |
||
| 357 | break; |
||
| 358 | View Code Duplication | case 160: // Entosis successful |
|
| 359 | $systemID = trim(explode(': ', $notificationString[2])[1]); |
||
| 360 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', 'solarSystemName', [':id' => $systemID], 'ccp'); |
||
| 361 | $msg = "Hostile entosis successful. A structure in **{$systemName}** has entered reinforced mode."; |
||
| 362 | break; |
||
| 363 | View Code Duplication | case 161: // Command Nodes Decloaking |
|
| 364 | $systemID = trim(explode(': ', $notificationString[2])[1]); |
||
| 365 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 366 | 'solarSystemName', [':id' => $systemID], 'ccp'); |
||
| 367 | $msg = "Command nodes decloaking for **{$systemName}**"; |
||
| 368 | break; |
||
| 369 | View Code Duplication | case 163: // Outpost freeport |
|
| 370 | $systemID = trim(explode(': ', $notificationString[1])[1]); |
||
| 371 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 372 | 'solarSystemName', [':id' => $systemID], 'ccp'); |
||
| 373 | $msg = "Station in **{$systemName}** has now entered freeport mode."; |
||
| 374 | break; |
||
| 375 | case 182: // Citadel being anchored |
||
| 376 | $corpName = trim(explode(': ', $notificationString[1])[1]); |
||
| 377 | $solarSystemID = trim(explode(': ', $notificationString[2])[1]); |
||
| 378 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 379 | 'solarSystemName', [':id' => $solarSystemID], 'ccp'); |
||
| 380 | $msg = "Citadel owned by **{$corpName}** is being anchored in **{$systemName}**."; |
||
| 381 | break; |
||
| 382 | case 184: // Citadel under attack |
||
| 383 | $aggID = trim(explode(': ', $notificationString[7])[1]); |
||
| 384 | $aggCharacterName = $this->apiData('char', $aggID)['characterName']; |
||
| 385 | $solarSystemID = trim(explode(': ', $notificationString[15])[1]); |
||
| 386 | $aggAllianceID = trim(explode(': ', $notificationString[0])[1]); |
||
| 387 | $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName']; |
||
| 388 | $aggCorpID = trim(explode('- ', $notificationString[11])[1]); |
||
| 389 | $aggCorpName = $this->apiData('corp', $aggCorpID)['corporationName']; |
||
| 390 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 391 | 'solarSystemName', [':id' => $solarSystemID], 'ccp'); |
||
| 392 | $msg = "@everyone | Citadel under attack in **{$systemName}** by **{$aggCharacterName}** ({$aggCorpName} / {$aggAllianceName})."; |
||
| 393 | break; |
||
| 394 | View Code Duplication | case 185: // Citadel online |
|
| 395 | $solarSystemID = trim(explode(': ', $notificationString[0])[1]); |
||
| 396 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 397 | 'solarSystemName', [':id' => $solarSystemID], 'ccp'); |
||
| 398 | $msg = "Citadel now online in **{$systemName}**."; |
||
| 399 | break; |
||
| 400 | View Code Duplication | case 188: // Citadel destroyed |
|
| 401 | $corpID = trim(explode('- ', $notificationString[3])[1]); |
||
| 402 | $corpName = $this->apiData('corp', $corpID)['corporationName']; |
||
| 403 | $solarSystemID = trim(explode(': ', $notificationString[5])[1]); |
||
| 404 | $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', |
||
| 405 | 'solarSystemName', [':id' => $solarSystemID], 'ccp'); |
||
| 406 | $msg = "Citadel owned by **{$corpName}** in **{$systemName}** has been destroyed."; |
||
| 407 | break; |
||
| 408 | case 199: // citadel delivery |
||
| 409 | $msg = 'skip'; |
||
| 410 | break; |
||
| 411 | default: // Unknown typeID |
||
| 412 | $string = implode(' ', $notificationString); |
||
| 413 | $msg = "typeID {$typeID} is an unmapped notification, send Mr Twinkie this whole message via evemail or github issue. {$string}"; |
||
| 414 | break; |
||
| 415 | } |
||
| 416 | |||
| 417 | if ($msg == 'skip') { |
||
| 418 | return; |
||
| 419 | } |
||
| 420 | if ($msg == '') { |
||
| 421 | } |
||
| 422 | $this->logger->addInfo("Notification sent to channel {$this->toDiscordChannel}, Message - {$msg}"); |
||
| 423 | $channelID = $this->toDiscordChannel; |
||
| 424 | $channel = Channel::find($channelID); |
||
| 425 | $channel->sendMessage($msg, false); |
||
| 426 | // Find the maxID so we don't output this message again in the future |
||
| 427 | $this->maxID = max($notificationID, $this->maxID); |
||
| 428 | $this->newestNotificationID = $this->maxID; |
||
| 429 | setPermCache('newestNotificationID', $this->maxID); |
||
| 430 | } |
||
| 431 | } |
||
| 432 | |||
| 433 | $this->logger->addInfo("Next Notification Check At: {$cacheTimer} EVE Time"); |
||
| 434 | } catch (Exception $e) { |
||
| 435 | $this->logger->addInfo('Notification Error: '.$e->getMessage()); |
||
| 436 | } |
||
| 437 | } |
||
| 438 | |||
| 497 |
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.