| Conditions | 76 |
| Paths | 16952 |
| Total Lines | 374 |
| Code Lines | 350 |
| Lines | 112 |
| Ratio | 29.95 % |
| 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 |
||
| 145 | function getNotifications($keyID, $vCode, $characterID) |
||
| 146 | { |
||
| 147 | $discord = $this->discord; |
||
| 148 | |||
| 149 | try { |
||
| 150 | $url = "https://api.eveonline.com/char/Notifications.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}"; |
||
| 151 | $xml = makeApiRequest($url); |
||
| 152 | date_default_timezone_set('UTC'); |
||
| 153 | $cached = $xml->cachedUntil[0]; |
||
| 154 | $baseUnix = strtotime($cached); |
||
| 155 | $cacheClr = $baseUnix - 13500; |
||
| 156 | if (!isset($this->fuelChannel)) { |
||
| 157 | $this->fuelChannel = $this->toDiscordChannel; |
||
| 158 | } |
||
| 159 | View Code Duplication | if ($cacheClr <= time()) { |
|
| 160 | $weirdTime = time() + 1830; |
||
| 161 | $cacheTimer = gmdate("Y-m-d H:i:s", $weirdTime); |
||
| 162 | setPermCache("notificationsLastChecked{$keyID}", $weirdTime); |
||
| 163 | } else { |
||
| 164 | $cacheTimer = gmdate("Y-m-d H:i:s", $cacheClr); |
||
| 165 | setPermCache("notificationsLastChecked{$keyID}", $cacheClr); |
||
| 166 | } |
||
| 167 | $data = json_decode(json_encode(simplexml_load_string(downloadData($url), |
||
| 168 | "SimpleXMLElement", LIBXML_NOCDATA)), true); |
||
| 169 | $data = $data["result"]["rowset"]["row"]; |
||
| 170 | // If there is no data, just quit.. |
||
| 171 | if (empty($data)) { |
||
| 172 | return; |
||
| 173 | } |
||
| 174 | $fixedData = array(); |
||
| 175 | // Sometimes there is only ONE notification, so.. yeah.. |
||
| 176 | if (isset($data["@attributes"])) { |
||
| 177 | $fixedData[] = $data["@attributes"]; |
||
| 178 | } |
||
| 179 | if (count($data) > 1) { |
||
| 180 | foreach ($data as $multiNotif) { |
||
| 181 | $fixedData[] = $multiNotif["@attributes"]; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | foreach ($fixedData as $notification) { |
||
| 185 | $notificationID = $notification["notificationID"]; |
||
| 186 | $typeID = $notification["typeID"]; |
||
| 187 | $sentDate = $notification["sentDate"]; |
||
| 188 | $channelID = $this->toDiscordChannel; |
||
| 189 | if ($notificationID > $this->newestNotificationID) { |
||
| 190 | $notificationString = explode("\n", $this->getNotificationText($keyID, $vCode, $characterID, |
||
| 191 | $notificationID)); |
||
| 192 | switch ($typeID) { |
||
| 193 | case 1: // Old |
||
| 194 | $msg = "skip"; |
||
| 195 | break; |
||
| 196 | case 2: // biomassed |
||
| 197 | $msg = "skip"; |
||
| 198 | break; |
||
| 199 | case 3: // medal awarded |
||
| 200 | $msg = "skip"; |
||
| 201 | break; |
||
| 202 | case 4: // alliance bill |
||
| 203 | $msg = "skip"; |
||
| 204 | break; |
||
| 205 | View Code Duplication | case 5: // War Declared |
|
| 206 | $defAllianceID = trim(explode(": ", $notificationString[0])[1]); |
||
| 207 | $aggAllianceID = trim(explode(": ", $notificationString[2])[1]); |
||
| 208 | $defAllianceName = apiCharacterName($defAllianceID); |
||
| 209 | $aggAllianceName = apiCharacterName($aggAllianceID); |
||
| 210 | $msg = "@everyone | War declared by {$aggAllianceName} against {$defAllianceName}. Fighting begins in roughly 24 hours."; |
||
| 211 | break; |
||
| 212 | case 6: // Corp joins war (Not enough info in api to say who the 3rd party is) |
||
| 213 | $defAllianceID = trim(explode(": ", $notificationString[0])[1]); |
||
| 214 | $aggAllianceID = trim(explode(": ", $notificationString[2])[1]); |
||
| 215 | $defAllianceName = apiCharacterName($defAllianceID); |
||
| 216 | $aggAllianceName = apiCharacterName($aggAllianceID); |
||
| 217 | $msg = "The war between {$aggAllianceName} and {$defAllianceName} has been joined by a third party. This new group may begin fighting in roughly 24 hours."; |
||
| 218 | break; |
||
| 219 | View Code Duplication | case 7: // War Declared corp |
|
| 220 | $defCorpID = trim(explode(": ", $notificationString[0])[1]); |
||
| 221 | $aggCorpID = trim(explode(": ", $notificationString[2])[1]); |
||
| 222 | $defCorpName = apiCharacterName($defCorpID); |
||
| 223 | $aggCorpName = apiCharacterName($aggCorpID); |
||
| 224 | $msg = "@everyone | War declared by {$aggCorpName} against {$defCorpName}. Fighting begins in roughly 24 hours."; |
||
| 225 | break; |
||
| 226 | View Code Duplication | case 8: // Alliance war invalidated by CONCORD |
|
| 227 | $aggAllianceID = trim(explode(": ", $notificationString[2])[1]); |
||
| 228 | $aggAllianceName = apiCharacterName($aggAllianceID); |
||
| 229 | $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours."; |
||
| 230 | break; |
||
| 231 | case 9: // Pilot bill |
||
| 232 | $msg = "skip"; |
||
| 233 | break; |
||
| 234 | case 10: // Bill issued |
||
| 235 | $msg = "skip"; |
||
| 236 | break; |
||
| 237 | case 11: // Bill stuff |
||
| 238 | $msg = "skip"; |
||
| 239 | break; |
||
| 240 | case 12: // Bill Stuff |
||
| 241 | $msg = "skip"; |
||
| 242 | break; |
||
| 243 | case 13: // Bill issued |
||
| 244 | $msg = "skip"; |
||
| 245 | break; |
||
| 246 | case 14: // Bounty payment |
||
| 247 | $msg = "skip"; |
||
| 248 | break; |
||
| 249 | case 16: // Mail |
||
| 250 | $msg = "skip"; |
||
| 251 | break; |
||
| 252 | case 17: // Corp app |
||
| 253 | $msg = "skip"; |
||
| 254 | break; |
||
| 255 | case 18: // Corp app |
||
| 256 | $msg = "skip"; |
||
| 257 | break; |
||
| 258 | case 19: // corp tax changed |
||
| 259 | $corpID = trim(explode(": ", $notificationString[0])[1]); |
||
| 260 | $corpName = apiCharacterName($corpID); |
||
| 261 | $oldTax = trim(explode(": ", $notificationString[2])[1]); |
||
| 262 | $newTax = trim(explode(": ", $notificationString[1])[1]); |
||
| 263 | $msg = "{$corpName} tax changed from {$oldTax}% to {$newTax}%"; |
||
| 264 | if ($this->allianceOnly == "true") { |
||
| 265 | $msg = "skip"; |
||
| 266 | } |
||
| 267 | break; |
||
| 268 | case 20: // Corp news? |
||
| 269 | $msg = "skip"; |
||
| 270 | break; |
||
| 271 | case 21: // member left corp |
||
| 272 | $msg = "skip"; |
||
| 273 | break; |
||
| 274 | View Code Duplication | case 31: // Alliance war invalidated by CONCORD |
|
| 275 | $aggAllianceID = trim(explode(": ", $notificationString[2])[1]); |
||
| 276 | $aggAllianceName = apiCharacterName($aggAllianceID); |
||
| 277 | $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours."; |
||
| 278 | break; |
||
| 279 | case 34: // Noob ship |
||
| 280 | $msg = "skip"; |
||
| 281 | break; |
||
| 282 | case 35: // Insurance payment |
||
| 283 | $msg = "skip"; |
||
| 284 | break; |
||
| 285 | View Code Duplication | case 41: // System lost |
|
| 286 | $solarSystemID = trim(explode(": ", $notificationString[2])[1]); |
||
| 287 | $systemName = apiCharacterName($solarSystemID); |
||
| 288 | $allianceID = trim(explode(": ", $notificationString[0])[1]); |
||
| 289 | $allianceName = apiCharacterName($allianceID); |
||
| 290 | $msg = "{$allianceName} has lost control of **{$systemName}**"; |
||
| 291 | break; |
||
| 292 | View Code Duplication | case 43: // System captured |
|
| 293 | $solarSystemID = trim(explode(": ", $notificationString[2])[1]); |
||
| 294 | $systemName = apiCharacterName($solarSystemID); |
||
| 295 | $allianceID = trim(explode(": ", $notificationString[0])[1]); |
||
| 296 | $allianceName = apiCharacterName($allianceID); |
||
| 297 | $msg = "{$allianceName} now controls **{$systemName}**"; |
||
| 298 | break; |
||
| 299 | case 45: // Tower anchoring |
||
| 300 | $msg = "skip"; |
||
| 301 | break; |
||
| 302 | case 52: // clone revoked |
||
| 303 | $msg = "skip"; |
||
| 304 | break; |
||
| 305 | case 54: // insurance |
||
| 306 | $msg = "skip"; |
||
| 307 | break; |
||
| 308 | case 57: // jump clone destruction |
||
| 309 | $msg = "skip"; |
||
| 310 | break; |
||
| 311 | case 71: // Mission Expiration |
||
| 312 | $msg = "skip"; |
||
| 313 | break; |
||
| 314 | case 75: // POS / POS Module under attack |
||
| 315 | $aggAllianceID = trim(explode(": ", $notificationString[0])[1]); |
||
| 316 | $aggAllianceName = apiCharacterName($aggAllianceID); |
||
| 317 | $aggCorpID = trim(explode(": ", $notificationString[1])[1]); |
||
| 318 | $aggCorpName = apiCharacterName($aggCorpID); |
||
| 319 | $aggID = trim(explode(": ", $notificationString[2])[1]); |
||
| 320 | $aggCharacterName = apiCharacterName($aggID); |
||
| 321 | $moonID = trim(explode(": ", $notificationString[5])[1]); |
||
| 322 | $moonName = apiCharacterName($moonID); |
||
| 323 | $solarSystemID = trim(explode(": ", $notificationString[7])[1]); |
||
| 324 | $typeID = trim(explode(": ", $notificationString[8])[1]); |
||
| 325 | $typeName = apiTypeName($typeID); |
||
| 326 | $systemName = apiCharacterName($solarSystemID); |
||
| 327 | $msg = "**{$typeName}** under attack in **{$systemName} - {$moonName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName})."; |
||
| 328 | if ($this->allianceOnly == "true") { |
||
| 329 | $msg = "skip"; |
||
| 330 | } |
||
| 331 | break; |
||
| 332 | case 76: // Tower resource alert |
||
| 333 | $moonID = trim(explode(": ", $notificationString[2])[1]); |
||
| 334 | $moonName = apiCharacterName($moonID); |
||
| 335 | $solarSystemID = trim(explode(": ", $notificationString[3])[1]); |
||
| 336 | $systemName = apiCharacterName($solarSystemID); |
||
| 337 | $blocksRemaining = trim(explode(": ", $notificationString[6])[1]); |
||
| 338 | $typeID = trim(explode(": ", $notificationString[7])[1]); |
||
| 339 | $channelID = $this->fuelChannel; |
||
| 340 | $typeName = apiTypeName($typeID); |
||
| 341 | $msg = "POS in {$systemName} - {$moonName} needs fuel. Only {$blocksRemaining} {$typeName}'s remaining."; |
||
| 342 | if ($this->fuelSkip == "true" || $this->allianceOnly == "true") { |
||
| 343 | $msg = "skip"; |
||
| 344 | } |
||
| 345 | |||
| 346 | break; |
||
| 347 | case 88: // IHUB is being attacked |
||
| 348 | $aggAllianceID = trim(explode(": ", $notificationString[0])[1]); |
||
| 349 | $aggAllianceName = apiCharacterName($aggAllianceID); |
||
| 350 | $aggCorpID = trim(explode(": ", $notificationString[0])[1]); |
||
| 351 | $aggCorpName = apiCharacterName($aggCorpID); |
||
| 352 | $aggID = trim(explode(": ", $notificationString[1])[1]); |
||
| 353 | $aggCharacterName = apiCharacterName($aggID); |
||
| 354 | $armorValue = trim(explode(": ", $notificationString[3])[1]); |
||
| 355 | $hullValue = trim(explode(": ", $notificationString[4])[1]); |
||
| 356 | $shieldValue = trim(explode(": ", $notificationString[5])[1]); |
||
| 357 | $solarSystemID = trim(explode(": ", $notificationString[6])[1]); |
||
| 358 | $systemName = apiCharacterName($solarSystemID); |
||
| 359 | $msg = "IHUB under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}"; |
||
| 360 | break; |
||
| 361 | case 93: // Customs office is being attacked |
||
| 362 | $aggAllianceID = trim(explode(": ", $notificationString[0])[1]); |
||
| 363 | $aggAllianceName = apiCharacterName($aggAllianceID); |
||
| 364 | $aggCorpID = trim(explode(": ", $notificationString[0])[1]); |
||
| 365 | $aggCorpName = apiCharacterName($aggCorpID); |
||
| 366 | $aggID = trim(explode(": ", $notificationString[2])[1]); |
||
| 367 | $aggCharacterName = apiCharacterName($aggID); |
||
| 368 | $shieldValue = trim(explode(": ", $notificationString[5])[1]); |
||
| 369 | $solarSystemID = trim(explode(": ", $notificationString[6])[1]); |
||
| 370 | $systemName = apiCharacterName($solarSystemID); |
||
| 371 | $msg = "Customs Office under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Shield Status: {$shieldValue}"; |
||
| 372 | if ($this->allianceOnly == "true") { |
||
| 373 | $msg = "skip"; |
||
| 374 | } |
||
| 375 | break; |
||
| 376 | case 94: // POCO Reinforced |
||
| 377 | $msg = "Customs Office reinforced."; |
||
| 378 | break; |
||
| 379 | case 95: // IHub Transfer |
||
| 380 | $msg = "skip"; |
||
| 381 | break; |
||
| 382 | View Code Duplication | case 100: // Aggressor corp joins war |
|
| 383 | $aggCorpID = trim(explode(": ", $notificationString[0])[1]); |
||
| 384 | $defCorpID = trim(explode(": ", $notificationString[1])[1]); |
||
| 385 | $aggCorpName = apiCharacterName($aggCorpID); |
||
| 386 | $defCorpName = apiCharacterName($defCorpID); |
||
| 387 | $msg = "{$aggCorpName} has joined the war against {$defCorpName}."; |
||
| 388 | break; |
||
| 389 | case 102: // War support offer? I think? |
||
| 390 | $msg = "skip"; |
||
| 391 | break; |
||
| 392 | case 103: // War support offer? I think? |
||
| 393 | $msg = "skip"; |
||
| 394 | break; |
||
| 395 | case 111: // Bounty |
||
| 396 | $msg = "skip"; |
||
| 397 | break; |
||
| 398 | case 128: // Corp App |
||
| 399 | $msg = "skip"; |
||
| 400 | break; |
||
| 401 | case 129: // App denied |
||
| 402 | $msg = "skip"; |
||
| 403 | break; |
||
| 404 | case 130: // Corp app withdrawn? |
||
| 405 | $msg = "skip"; |
||
| 406 | break; |
||
| 407 | case 135: // ESS stolen |
||
| 408 | $msg = "skip"; |
||
| 409 | break; |
||
| 410 | case 138: // Clone activation |
||
| 411 | $msg = "skip"; |
||
| 412 | break; |
||
| 413 | case 140: // Kill report |
||
| 414 | $msg = "skip"; |
||
| 415 | break; |
||
| 416 | case 141: // Kill report |
||
| 417 | $msg = "skip"; |
||
| 418 | break; |
||
| 419 | View Code Duplication | case 147: // Entosis has started |
|
| 420 | $solarSystemID = trim(explode(": ", $notificationString[0])[1]); |
||
| 421 | $systemName = apiCharacterName($solarSystemID); |
||
| 422 | $typeID = trim(explode(": ", $notificationString[1])[1]); |
||
| 423 | $typeName = apiTypeName($typeID); |
||
| 424 | $msg = "Entosis has started in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)"; |
||
| 425 | break; |
||
| 426 | View Code Duplication | case 148: // Entosis enabled a module ?????? |
|
| 427 | $solarSystemID = trim(explode(": ", $notificationString[0])[1]); |
||
| 428 | $systemName = apiCharacterName($solarSystemID); |
||
| 429 | $typeID = trim(explode(": ", $notificationString[1])[1]); |
||
| 430 | $typeName = apiTypeName($typeID); |
||
| 431 | $msg = "Entosis has enabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)"; |
||
| 432 | break; |
||
| 433 | View Code Duplication | case 149: // Entosis disabled a module |
|
| 434 | $solarSystemID = trim(explode(": ", $notificationString[0])[1]); |
||
| 435 | $systemName = apiCharacterName($solarSystemID); |
||
| 436 | $typeID = trim(explode(": ", $notificationString[1])[1]); |
||
| 437 | $typeName = apiTypeName($typeID); |
||
| 438 | $msg = "Entosis has disabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)"; |
||
| 439 | break; |
||
| 440 | case 152: // Sov bill |
||
| 441 | $msg = "skip"; |
||
| 442 | break; |
||
| 443 | View Code Duplication | case 160: // Entosis successful |
|
| 444 | $solarSystemID = trim(explode(": ", $notificationString[2])[1]); |
||
| 445 | $systemName = apiCharacterName($solarSystemID); |
||
| 446 | $msg = "Hostile entosis successful. A structure in **{$systemName}** has entered reinforced mode."; |
||
| 447 | break; |
||
| 448 | View Code Duplication | case 161: // Command Nodes Decloaking |
|
| 449 | $solarSystemID = trim(explode(": ", $notificationString[2])[1]); |
||
| 450 | $systemName = apiCharacterName($solarSystemID); |
||
| 451 | $msg = "Command nodes decloaking for **{$systemName}**"; |
||
| 452 | break; |
||
| 453 | View Code Duplication | case 162: // TCU Destroyed |
|
| 454 | $solarSystemID = trim(explode(": ", $notificationString[0])[1]); |
||
| 455 | $systemName = apiCharacterName($solarSystemID); |
||
| 456 | $msg = "Entosis successful, TCU in **{$systemName}** has been destroyed."; |
||
| 457 | break; |
||
| 458 | View Code Duplication | case 163: // Outpost freeport |
|
| 459 | $solarSystemID = trim(explode(": ", $notificationString[1])[1]); |
||
| 460 | $systemName = apiCharacterName($solarSystemID); |
||
| 461 | $msg = "Station in **{$systemName}** has now entered freeport mode."; |
||
| 462 | break; |
||
| 463 | View Code Duplication | case 182: // Citadel being anchored |
|
| 464 | $corpName = trim(explode(": ", $notificationString[1])[1]); |
||
| 465 | $solarSystemID = trim(explode(": ", $notificationString[2])[1]); |
||
| 466 | $systemName = apiCharacterName($solarSystemID); |
||
| 467 | $msg = "Citadel owned by **{$corpName}** is being anchored in **{$systemName}**."; |
||
| 468 | break; |
||
| 469 | case 184: // Citadel under attack |
||
| 470 | $aggID = trim(explode(": ", $notificationString[7])[1]); |
||
| 471 | $aggCharacterName = apiCharacterName($aggID); |
||
| 472 | $solarSystemID = trim(explode(": ", $notificationString[15])[1]); |
||
| 473 | $aggAllianceID = trim(explode(": ", $notificationString[0])[1]); |
||
| 474 | $aggAllianceName = apiCharacterName($aggAllianceID); |
||
| 475 | $aggCorpID = trim(explode("- ", $notificationString[11])[1]); |
||
| 476 | $aggCorpName = apiCharacterName($aggCorpID); |
||
| 477 | $systemName = apiCharacterName($solarSystemID); |
||
| 478 | $msg = "@everyone | Citadel under attack in **{$systemName}** by **{$aggCharacterName}** ({$aggCorpName} / {$aggAllianceName})."; |
||
| 479 | break; |
||
| 480 | View Code Duplication | case 185: // Citadel online |
|
| 481 | $solarSystemID = trim(explode(": ", $notificationString[0])[1]); |
||
| 482 | $systemName = apiCharacterName($solarSystemID); |
||
| 483 | $msg = "Citadel now online in **{$systemName}**."; |
||
| 484 | break; |
||
| 485 | View Code Duplication | case 188: // Citadel destroyed |
|
| 486 | $corpID = trim(explode("- ", $notificationString[3])[1]); |
||
| 487 | $corpName = apiCharacterName($corpID); |
||
| 488 | $solarSystemID = trim(explode(": ", $notificationString[5])[1]); |
||
| 489 | $systemName = apiCharacterName($solarSystemID); |
||
| 490 | $msg = "Citadel owned by **{$corpName}** in **{$systemName}** has been destroyed."; |
||
| 491 | break; |
||
| 492 | case 199: // citadel delivery |
||
| 493 | $msg = "skip"; |
||
| 494 | break; |
||
| 495 | default: // Unknown typeID |
||
| 496 | $string = implode(" ", $notificationString); |
||
| 497 | $msg = "typeID {$typeID} is an unmapped notification, please create a Github issue with this entire message and please include what the in-game notification is. {$string}"; |
||
| 498 | break; |
||
| 499 | } |
||
| 500 | |||
| 501 | if ($msg == "skip") { |
||
| 502 | return null; |
||
| 503 | } |
||
| 504 | $this->logger->addInfo("Notifications: Notification queued, Message - {$msg}"); |
||
| 505 | priorityQueueMessage($msg, $channelID, $this->guild); |
||
| 506 | // Find the maxID so we don't output this message again in the future |
||
| 507 | $this->maxID = max($notificationID, $this->maxID); |
||
| 508 | $this->newestNotificationID = $this->maxID; |
||
| 509 | setPermCache("newestNotificationID", $this->maxID); |
||
| 510 | } |
||
| 511 | } |
||
| 512 | |||
| 513 | $this->logger->addInfo("Notifications: Next Notification Check At: {$cacheTimer} EVE Time"); |
||
| 514 | } catch (Exception $e) { |
||
| 515 | $this->logger->addInfo("Notifications: Notification Error: " . $e->getMessage()); |
||
| 516 | } |
||
| 517 | return null; |
||
| 518 | } |
||
| 519 | |||
| 555 |
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.