| Conditions | 6 |
| Paths | 38 |
| Total Lines | 51 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 38 | public function handle(MojangClient $mojangClient): int |
||
| 39 | { |
||
| 40 | $this->info('Selecting old uuid...'); |
||
| 41 | |||
| 42 | $results = $this->getAccountsIds(); |
||
| 43 | |||
| 44 | foreach ($results as $result) { |
||
| 45 | /** @var \Minepic\Models\Account $account */ |
||
| 46 | $account = Account::find($result->id); |
||
| 47 | if ($account) { |
||
| 48 | $this->info("Checking {$account->username} [{$account->uuid}]..."); |
||
| 49 | try { |
||
| 50 | $accountApiData = $mojangClient->getUuidInfo($account->uuid); |
||
| 51 | $this->info("\tUUID Valid"); |
||
| 52 | |||
| 53 | // Update database |
||
| 54 | $account->update([ |
||
| 55 | 'username' => $accountApiData->getUsername(), |
||
| 56 | 'skin' => $accountApiData->getSkin(), |
||
| 57 | 'cape' => $accountApiData->getCape(), |
||
| 58 | 'fail_count' => 0, |
||
| 59 | ]); |
||
| 60 | $this->info("\tData updated"); |
||
| 61 | |||
| 62 | try { |
||
| 63 | $skinData = $mojangClient->getSkin($account->uuid); |
||
| 64 | SkinsStorage::save($account->uuid, $skinData); |
||
| 65 | $this->info("\tSkin png updated"); |
||
| 66 | } catch (\Exception $e) { |
||
| 67 | SkinsStorage::copyAsSteve($account->uuid); |
||
| 68 | $this->error("\tUsing Steve as skin"); |
||
| 69 | $this->error("\t".$e->getMessage()); |
||
| 70 | } |
||
| 71 | } catch (\Exception $e) { |
||
| 72 | ++$account->fail_count; |
||
| 73 | $account->update([ |
||
| 74 | 'fail_count' => $account->fail_count, |
||
| 75 | ]); |
||
| 76 | $this->warn("\tFailed. Fail count: {$account->fail_count}"); |
||
| 77 | if ($account->fail_count > 10) { |
||
| 78 | $account->delete(); |
||
| 79 | $this->error("\tDELETED!"); |
||
| 80 | } else { |
||
| 81 | $account->save(); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | $this->line('################################################'); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | return 0; |
||
| 89 | } |
||
| 101 |