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