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