| Conditions | 5 |
| Paths | 8 |
| Total Lines | 65 |
| 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 |
||
| 55 | public function check(InputInterface $input, OutputInterface $output) |
||
| 56 | { |
||
| 57 | $obj = new \DateTime(); |
||
| 58 | $obj->sub(new \DateInterval('P3D')); |
||
| 59 | |||
| 60 | $query = $this->alertRepo->newQuery(); |
||
| 61 | $query->cols(['*']); |
||
| 62 | $query->where('ResultStartTime < ?', $obj->format('U')); |
||
| 63 | $query->where('Archived = 0'); |
||
| 64 | |||
| 65 | if (!empty($input->getArgument('start'))) { |
||
| 66 | $query->where('ResultID >= ?', $input->getArgument('start')); |
||
| 67 | } |
||
| 68 | |||
| 69 | if (!empty($input->getArgument('process'))) { |
||
| 70 | $query->where('ResultID <= ?', $input->getArgument('process')); |
||
| 71 | } |
||
| 72 | |||
| 73 | $alerts = $this->alertRepo->fireStatementAndReturn($query); |
||
| 74 | $count = count($alerts); |
||
| 75 | |||
| 76 | $output->writeln("Detected {$count} alerts to be archived"); |
||
| 77 | |||
| 78 | if ($count > 0) { |
||
| 79 | $tables = [ |
||
| 80 | 'ws_classes', |
||
| 81 | 'ws_classes_totals', |
||
| 82 | 'ws_combat_history', |
||
| 83 | 'ws_factions', |
||
| 84 | 'ws_map', |
||
| 85 | 'ws_map_initial', |
||
| 86 | 'ws_outfits', |
||
| 87 | 'ws_players', |
||
| 88 | 'ws_pops', |
||
| 89 | 'ws_vehicles', |
||
| 90 | 'ws_weapons', |
||
| 91 | 'ws_xp' |
||
| 92 | ]; |
||
| 93 | |||
| 94 | for ($i = 0; $i < $count; $i++) { |
||
| 95 | $this->archive($alerts[$i], $tables, $output); |
||
| 96 | |||
| 97 | $per = ($i / $count) * 100; |
||
| 98 | $per = round($per, 2); |
||
| 99 | $output->writeln("{$i} / {$count} ({$per}%) processed"); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | $records = number_format($this->recordsArchived, 0); |
||
| 104 | |||
| 105 | $payload = [ |
||
| 106 | 'channel' => '#logs', |
||
| 107 | 'username' => 'ps2alerts-archive', |
||
| 108 | 'text' => "Alerts archived: {$this->alertsArchived} - Records archived: {$records}", |
||
| 109 | 'icon_emoji' => ':open_file_folder:' |
||
| 110 | ]; |
||
| 111 | |||
| 112 | $this->guzzle->request( |
||
| 113 | 'POST', |
||
| 114 | 'https://hooks.slack.com/services/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', |
||
| 115 | ['json' => $payload] |
||
| 116 | ); |
||
| 117 | |||
| 118 | $output->writeln("Archived {$records} records!"); |
||
| 119 | } |
||
| 120 | |||
| 235 |