| Conditions | 28 |
| Paths | 534 |
| Total Lines | 131 |
| Code Lines | 91 |
| Lines | 32 |
| Ratio | 24.43 % |
| 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 |
||
| 255 | private function nameReset() |
||
| 256 | { |
||
| 257 | //Get guild object |
||
| 258 | $guild = $this->discord->guilds->get('id', $this->guildID); |
||
| 259 | |||
| 260 | //Get name queue status |
||
| 261 | $x = (int) getPermCache('nameQueueState'); |
||
| 262 | |||
| 263 | //Establish connection to mysql |
||
| 264 | $conn = new mysqli($this->db, $this->dbUser, $this->dbPass, $this->dbName); |
||
| 265 | $sql = "SELECT id FROM authUsers WHERE active='yes'"; |
||
| 266 | $count = $conn->query($sql); |
||
| 267 | $rowAmount = round($count->num_rows / 2); |
||
| 268 | if ($x === 1) { |
||
| 269 | $sql = "SELECT characterID, discordID, eveName FROM authUsers WHERE active='yes' ORDER BY id ASC LIMIT {$rowAmount} OFFSET {$rowAmount}"; |
||
| 270 | setPermCache('nameQueueState', 0); |
||
| 271 | } else { |
||
| 272 | $sql = "SELECT characterID, discordID, eveName FROM authUsers WHERE active='yes' ORDER BY id ASC LIMIT {$rowAmount}"; |
||
| 273 | setPermCache('nameQueueState', 1); |
||
| 274 | } |
||
| 275 | $result = $conn->query($sql); |
||
| 276 | |||
| 277 | if (@$result->num_rows >= 1) { |
||
| 278 | while ($rows = $result->fetch_assoc()) { |
||
| 279 | $charID = $rows['characterID']; |
||
| 280 | $discordID = $rows['discordID']; |
||
| 281 | $member = $guild->members->get('id', $discordID); |
||
| 282 | $eveName = $rows['eveName']; |
||
| 283 | //Check if member has roles |
||
| 284 | if (null === @$member->roles) { |
||
| 285 | continue; |
||
| 286 | } |
||
| 287 | |||
| 288 | //Get current nickname |
||
| 289 | $guild = $this->discord->guilds->get('id', $this->guildID); |
||
| 290 | $member = $guild->members->get('id', $discordID); |
||
| 291 | $nickName = $member->nick; |
||
| 292 | $userName = $member->user->username; |
||
| 293 | //If nick isn't set than make it username |
||
| 294 | if ($nickName === '' || null === $nickName) { |
||
| 295 | $nickName = $userName; |
||
| 296 | } |
||
| 297 | |||
| 298 | //Check for bad tickers |
||
| 299 | if (strpos($nickName, '[U]') !== false) { |
||
| 300 | $nickName = str_replace('[U]', '', $nickName); |
||
| 301 | queueRename($discordID, $nickName, $this->guildID); |
||
| 302 | continue; |
||
| 303 | } |
||
| 304 | |||
| 305 | //corp ticker |
||
| 306 | if ($this->corpTickers === 'true') { |
||
| 307 | $timeout = 0; |
||
| 308 | $character = characterDetails($charID); |
||
| 309 | while (null === $character) { //try 10 times to pull characterDetails |
||
| 310 | if ($timeout > 9) { |
||
| 311 | continue; |
||
| 312 | } |
||
| 313 | else{ |
||
| 314 | $character = characterDetails($charID); |
||
| 315 | $timeout++; |
||
| 316 | } |
||
| 317 | } |
||
| 318 | if (!array_key_exists('corporation_id', $character)) { |
||
| 319 | continue; |
||
| 320 | } |
||
| 321 | $corpInfo = getCorpInfo($character['corporation_id']); |
||
| 322 | //Clean bad entries |
||
| 323 | if (@$corpInfo['corpTicker'] === 'U') { |
||
| 324 | deleteCorpInfo(@$corpInfo['corpID']); |
||
| 325 | } |
||
| 326 | $nick = null; |
||
| 327 | View Code Duplication | if (null !== @$corpInfo['corpTicker']) { |
|
| 328 | $corpTicker = (string) $corpInfo['corpTicker']; |
||
| 329 | if ($this->nameEnforce === 'true') { |
||
| 330 | $nick = "[{$corpTicker}] {$eveName}"; |
||
| 331 | } elseif ((string) $nickName === "[{$corpTicker}]") { |
||
| 332 | $nick = "[{$corpTicker}] {$userName}"; |
||
| 333 | } elseif (strpos($nickName, $corpTicker) === false) { |
||
| 334 | $nick = "[{$corpTicker}] {$nickName}"; |
||
| 335 | } elseif (strpos($nickName, $corpTicker) !== false) { |
||
| 336 | continue; |
||
| 337 | } |
||
| 338 | if ($nick !== $nickName) { |
||
| 339 | queueRename($discordID, $nick, $this->guildID); |
||
| 340 | } |
||
| 341 | continue; |
||
| 342 | } |
||
| 343 | $corporationDetails = corpDetails($character['corporation_id']); |
||
| 344 | if (null === $corporationDetails) { |
||
| 345 | continue; |
||
| 346 | } |
||
| 347 | $corpTicker = $corporationDetails['ticker']; |
||
| 348 | //Check for bad tickers (ESI ERROR?) |
||
| 349 | if (@$corpTicker === 'U') { |
||
| 350 | continue; |
||
| 351 | } |
||
| 352 | $corpName = (string) $corporationDetails['corporation_name']; |
||
| 353 | View Code Duplication | if (null !== $corpTicker) { |
|
| 354 | if ($this->nameEnforce === 'true') { |
||
| 355 | $nick = "[{$corpTicker}] {$eveName}"; |
||
| 356 | } elseif ((string) $nickName === "[{$corpTicker}]") { |
||
| 357 | $nick = "[{$corpTicker}] {$userName}"; |
||
| 358 | } elseif (strpos($nickName, $corpTicker) === false) { |
||
| 359 | $nick = "[{$corpTicker}] {$nickName}"; |
||
| 360 | } elseif (strpos($nickName, $corpTicker) !== false) { |
||
| 361 | continue; |
||
| 362 | } |
||
| 363 | if ($nick !== $nickName) { |
||
| 364 | queueRename($discordID, $nick, $this->guildID); |
||
| 365 | addCorpInfo($character['corporation_id'], $corpTicker, $corpName); |
||
| 366 | } |
||
| 367 | continue; |
||
| 368 | } |
||
| 369 | continue; |
||
| 370 | } |
||
| 371 | $nick = "{$eveName}"; |
||
| 372 | if ($nick !== $nickName) { |
||
| 373 | queueRename($discordID, $nick, $this->guildID); |
||
| 374 | } |
||
| 375 | continue; |
||
| 376 | } |
||
| 377 | $nextCheck = time() + 1800; |
||
| 378 | setPermCache('nextRename', $nextCheck); |
||
| 379 | return null; |
||
| 380 | } |
||
| 381 | $nextCheck = time() + 1800; |
||
| 382 | setPermCache('nextRename', $nextCheck); |
||
| 383 | return null; |
||
| 384 | |||
| 385 | } |
||
| 386 | |||
| 411 |
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.