| Conditions | 25 |
| Paths | 18 |
| Total Lines | 110 |
| Code Lines | 78 |
| Lines | 27 |
| Ratio | 24.55 % |
| 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 |
||
| 317 | function nameReset() |
||
| 318 | { |
||
| 319 | //Get guild object |
||
| 320 | $guild = $this->discord->guilds->get('id', $this->guildID); |
||
| 321 | |||
| 322 | //Establish connection to mysql |
||
| 323 | $conn = new mysqli($this->db, $this->dbUser, $this->dbPass, $this->dbName); |
||
| 324 | $sql = "SELECT characterID, discordID, eveName FROM authUsers WHERE active='yes'"; |
||
| 325 | $result = $conn->query($sql); |
||
| 326 | |||
| 327 | // If config is outdated |
||
| 328 | View Code Duplication | if (is_null($this->authGroups)) { |
|
| 329 | $msg = "**Auth Failure:** Please update the bots config to the latest version."; |
||
| 330 | queueMessage($msg, $this->alertChannel, $this->guild); |
||
| 331 | $nextCheck = time() + 10800; |
||
| 332 | setPermCache("permsLastChecked", $nextCheck); |
||
| 333 | return null; |
||
| 334 | } |
||
| 335 | |||
| 336 | if ($result->num_rows >= 1) { |
||
| 337 | while ($rows = $result->fetch_assoc()) { |
||
| 338 | $charID = $rows['characterID']; |
||
| 339 | $discordID = $rows['discordID']; |
||
| 340 | $member = $guild->members->get("id", $discordID); |
||
| 341 | $eveName = $rows['eveName']; |
||
| 342 | //Check if member has roles |
||
| 343 | if (is_null($member->roles)) { |
||
| 344 | continue; |
||
| 345 | } |
||
| 346 | |||
| 347 | //Get current nickname |
||
| 348 | $guild = $this->discord->guilds->get('id', $this->guildID); |
||
| 349 | $member = $guild->members->get("id", $discordID); |
||
| 350 | $nickName = $member->nick; |
||
| 351 | $userName = $member->user->username; |
||
| 352 | //If nick isn't set than make it username |
||
| 353 | if ($nickName == "" || is_null($nickName)) { |
||
| 354 | $nickName = $userName; |
||
| 355 | } |
||
| 356 | |||
| 357 | //Get ingame affiliations |
||
| 358 | if ($this->corpTickers == "true") { |
||
| 359 | $url = "https://api.eveonline.com/eve/CharacterAffiliation.xml.aspx?ids=$charID"; |
||
| 360 | $xml = makeApiRequest($url); |
||
| 361 | // Stop the process if the api is throwing an error |
||
| 362 | if (is_null($xml)) { |
||
| 363 | $this->logger->addInfo("{$eveName} cannot be authed, API issues detected."); |
||
| 364 | return null; |
||
| 365 | } |
||
| 366 | if ($xml->result->rowset->row[0]) { |
||
| 367 | foreach ($xml->result->rowset->row as $character) { |
||
| 368 | $corpInfo = getCorpInfo($character->attributes()->corporationID); |
||
| 369 | if (!is_null($corpInfo)) { |
||
| 370 | $corpTicker = $corpInfo['corpTicker']; |
||
| 371 | View Code Duplication | if ($this->nameEnforce == "true") { |
|
| 372 | $nick = "[{$corpTicker}] {$eveName}"; |
||
| 373 | } elseif ($nickName == "[{$corpTicker}]") { |
||
| 374 | $nick = "[{$corpTicker}] {$userName}"; |
||
| 375 | } elseif (strpos($nickName, $corpTicker) == false) { |
||
| 376 | $nick = "[{$corpTicker}] {$nickName}"; |
||
| 377 | } elseif (strpos($nickName, $corpTicker) !== false) { |
||
| 378 | $nick = "{$nickName}"; |
||
| 379 | continue; |
||
| 380 | } |
||
| 381 | if ($nick != $nickName) { |
||
| 382 | queueRename($discordID, $nick, $this->guildID); |
||
| 383 | } |
||
| 384 | continue; |
||
| 385 | } |
||
| 386 | $url = "https://api.eveonline.com/corp/CorporationSheet.xml.aspx?corporationID={$character->attributes()->corporationID}"; |
||
| 387 | $xml = makeApiRequest($url); |
||
| 388 | $corpTicker = ""; |
||
| 389 | $corpName = ""; |
||
| 390 | foreach ($xml->result as $corporation) { |
||
| 391 | $corpTicker = $corporation->ticker; |
||
| 392 | $corpName = $corporation->corporationName; |
||
| 393 | } |
||
| 394 | View Code Duplication | if ($this->nameEnforce == "true") { |
|
| 395 | $nick = "[{$corpTicker}] {$eveName}"; |
||
| 396 | } elseif ($nickName == "[{$corpTicker}]") { |
||
| 397 | $nick = "[{$corpTicker}] {$userName}"; |
||
| 398 | } elseif (strpos($nickName, $corpTicker) == false) { |
||
| 399 | $nick = "[{$corpTicker}] {$nickName}"; |
||
| 400 | } elseif (strpos($nickName, $corpTicker) !== false) { |
||
| 401 | $nick = "{$nickName}"; |
||
| 402 | continue; |
||
| 403 | } |
||
| 404 | if ($nick != $nickName) { |
||
| 405 | queueRename($discordID, $nick, $this->guildID); |
||
| 406 | } |
||
| 407 | addCorpInfo($character->attributes()->corporationID, $corpTicker, $corpName); |
||
| 408 | continue; |
||
| 409 | } |
||
| 410 | } |
||
| 411 | } |
||
| 412 | $nick = "{$eveName}"; |
||
| 413 | if ($nick != $nickName && $this->corpTickers != "true") { |
||
| 414 | queueRename($discordID, $nick, $this->guildID); |
||
| 415 | } |
||
| 416 | continue; |
||
| 417 | } |
||
| 418 | $nextCheck = time() + 43200; |
||
| 419 | setPermCache("nameStateLastChecked", $nextCheck); |
||
| 420 | return null; |
||
| 421 | } |
||
| 422 | $nextCheck = time() + 43200; |
||
| 423 | setPermCache("nameStateLastChecked", $nextCheck); |
||
| 424 | return null; |
||
| 425 | |||
| 426 | } |
||
| 427 | } |
||
| 428 |
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.