| Conditions | 26 |
| Paths | 36 |
| Total Lines | 122 |
| Code Lines | 87 |
| Lines | 27 |
| Ratio | 22.13 % |
| 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 |
||
| 289 | private function nameReset() |
||
| 290 | { |
||
| 291 | //Get guild object |
||
| 292 | $guild = $this->discord->guilds->get('id', $this->guildID); |
||
| 293 | |||
| 294 | //Get name queue status |
||
| 295 | $x = (int)getPermCache('nameQueueState'); |
||
| 296 | |||
| 297 | //Establish connection to mysql |
||
| 298 | $conn = new mysqli($this->db, $this->dbUser, $this->dbPass, $this->dbName); |
||
| 299 | $sql = "SELECT id FROM authUsers WHERE active='yes'"; |
||
| 300 | $count = $conn->query($sql); |
||
| 301 | $rowAmount = $count->num_rows / 2; |
||
| 302 | if ($x == 1) { |
||
| 303 | $sql = "SELECT characterID, discordID, eveName FROM authUsers WHERE active='yes' ORDER BY id ASC LIMIT {$rowAmount} OFFSET {$rowAmount}"; |
||
| 304 | setPermCache('nameQueueState', 0); |
||
| 305 | } else { |
||
| 306 | $sql = "SELECT characterID, discordID, eveName FROM authUsers WHERE active='yes' ORDER BY id ASC LIMIT {$rowAmount}"; |
||
| 307 | setPermCache('nameQueueState', 1); |
||
| 308 | } |
||
| 309 | $result = $conn->query($sql); |
||
| 310 | |||
| 311 | // If config is outdated |
||
| 312 | View Code Duplication | if (null === $this->authGroups) { |
|
| 313 | $msg = '**Auth Failure:** Please update the bots config to the latest version.'; |
||
| 314 | queueMessage($msg, $this->alertChannel, $this->guild); |
||
| 315 | $nextCheck = time() + 1800; |
||
| 316 | setPermCache('nextRename', $nextCheck); |
||
| 317 | return null; |
||
| 318 | } |
||
| 319 | |||
| 320 | if (@$result->num_rows >= 1) { |
||
| 321 | while ($rows = $result->fetch_assoc()) { |
||
| 322 | $charID = $rows['characterID']; |
||
| 323 | $discordID = $rows['discordID']; |
||
| 324 | $member = $guild->members->get('id', $discordID); |
||
| 325 | $eveName = $rows['eveName']; |
||
| 326 | //Check if member has roles |
||
| 327 | if (null === $member->roles) { |
||
| 328 | continue; |
||
| 329 | } |
||
| 330 | |||
| 331 | //Get current nickname |
||
| 332 | $guild = $this->discord->guilds->get('id', $this->guildID); |
||
| 333 | $member = $guild->members->get('id', $discordID); |
||
| 334 | $nickName = $member->nick; |
||
| 335 | $userName = $member->user->username; |
||
| 336 | //If nick isn't set than make it username |
||
| 337 | if ($nickName == '' || null === $nickName) { |
||
| 338 | $nickName = $userName; |
||
| 339 | } |
||
| 340 | |||
| 341 | //Get ingame affiliations |
||
| 342 | if ($this->corpTickers === 'true') { |
||
| 343 | $url = "https://api.eveonline.com/eve/CharacterAffiliation.xml.aspx?ids=$charID"; |
||
| 344 | $xml = makeApiRequest($url); |
||
| 345 | // Stop the process if the api is throwing an error |
||
| 346 | if (null === $xml) { |
||
| 347 | $this->logger->addInfo("{$eveName} cannot be authed, API issues detected."); |
||
| 348 | return null; |
||
| 349 | } |
||
| 350 | if ($xml->result->rowset->row[0]) { |
||
| 351 | foreach ($xml->result->rowset->row as $character) { |
||
| 352 | $corpInfo = getCorpInfo($character->attributes()->corporationID); |
||
| 353 | if (null !== $corpInfo) { |
||
| 354 | $corpTicker = (string)$corpInfo['corpTicker']; |
||
| 355 | View Code Duplication | if ($this->nameEnforce === 'true') { |
|
| 356 | $nick = "[{$corpTicker}] {$eveName}"; |
||
| 357 | } elseif ((string)$nickName === "[{$corpTicker}]") { |
||
| 358 | $nick = "[{$corpTicker}] {$userName}"; |
||
| 359 | } elseif (strpos($nickName, $corpTicker) == false) { |
||
| 360 | $nick = "[{$corpTicker}] {$nickName}"; |
||
| 361 | } elseif (strpos($nickName, $corpTicker) !== false) { |
||
| 362 | $nick = "{$nickName}"; |
||
| 363 | continue; |
||
| 364 | } |
||
| 365 | if ($nick != $nickName) { |
||
| 366 | queueRename($discordID, $nick, $this->guildID); |
||
| 367 | } |
||
| 368 | continue; |
||
| 369 | } |
||
| 370 | $url = "https://api.eveonline.com/corp/CorporationSheet.xml.aspx?corporationID={$character->attributes()->corporationID}"; |
||
| 371 | $xml = makeApiRequest($url); |
||
| 372 | $corpTicker = ''; |
||
| 373 | $corpName = ''; |
||
| 374 | foreach ($xml->result as $corporation) { |
||
| 375 | $corpTicker = $corporation->ticker; |
||
| 376 | $corpName = $corporation->corporationName; |
||
| 377 | } |
||
| 378 | View Code Duplication | if ($this->nameEnforce === 'true') { |
|
| 379 | $nick = "[{$corpTicker}] {$eveName}"; |
||
| 380 | } elseif ((string)$nickName === "[{$corpTicker}]") { |
||
| 381 | $nick = "[{$corpTicker}] {$userName}"; |
||
| 382 | } elseif (strpos($nickName, $corpTicker) == false) { |
||
| 383 | $nick = "[{$corpTicker}] {$nickName}"; |
||
| 384 | } elseif (strpos($nickName, $corpTicker) !== false) { |
||
| 385 | $nick = "{$nickName}"; |
||
| 386 | continue; |
||
| 387 | } |
||
| 388 | if ($nick !== $nickName) { |
||
| 389 | queueRename($discordID, $nick, $this->guildID); |
||
| 390 | } |
||
| 391 | addCorpInfo($character->attributes()->corporationID, $corpTicker, $corpName); |
||
| 392 | continue; |
||
| 393 | } |
||
| 394 | } |
||
| 395 | } |
||
| 396 | $nick = "{$eveName}"; |
||
| 397 | if ($nick !== $nickName && $this->corpTickers !== 'true') { |
||
| 398 | queueRename($discordID, $nick, $this->guildID); |
||
| 399 | } |
||
| 400 | continue; |
||
| 401 | } |
||
| 402 | $nextCheck = time() + 1800; |
||
| 403 | setPermCache('nextRename', $nextCheck); |
||
| 404 | return null; |
||
| 405 | } |
||
| 406 | $nextCheck = time() + 1800; |
||
| 407 | setPermCache('nextRename', $nextCheck); |
||
| 408 | return null; |
||
| 409 | |||
| 410 | } |
||
| 411 | } |
||
| 412 |
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.