| Conditions | 10 |
| Paths | 27 |
| Total Lines | 63 |
| Code Lines | 41 |
| 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 |
||
| 30 | public function checkPlayerLeaderboards(OutputInterface $output) |
||
| 31 | { |
||
| 32 | $output->writeln("Checking Player Leaderboards"); |
||
| 33 | $date = date('U'); |
||
| 34 | $deadline = $date - 21600; // 6 hours ago |
||
| 35 | |||
| 36 | $servers = $this->config['servers']; |
||
| 37 | $servers[] = 0; |
||
| 38 | |||
| 39 | foreach ($servers as $server) { |
||
| 40 | $output->writeln("Checking Server {$server}"); |
||
| 41 | |||
| 42 | $key = "ps2alerts:api:leaderboards:status:{$server}"; |
||
| 43 | $resultKey = "ps2alerts:api:leaderboards:lastResult:{$server}"; |
||
| 44 | |||
| 45 | if (!$this->redis->exists($key)) { |
||
| 46 | $output->writeln("Key doesn't exist for server {$server}! Forcing!"); |
||
| 47 | $this->update($server, $output); |
||
| 48 | continue; |
||
| 49 | } |
||
| 50 | |||
| 51 | $data = json_decode($this->redis->get($key), true); |
||
| 52 | |||
| 53 | if ($data['beingUpdated'] == 1) { |
||
| 54 | $output->writeln("Server {$server} is currently being updated. Deferring."); |
||
| 55 | continue; |
||
| 56 | } |
||
| 57 | |||
| 58 | $query = $this->auraFactory->newSelect(); |
||
| 59 | $query->cols(['ResultID']); |
||
| 60 | $query->from('ws_results'); |
||
| 61 | if ($server !== 0) { |
||
| 62 | $query->where('ResultServer = ?', $server); |
||
| 63 | } |
||
| 64 | $query->where('InProgress = ?', 0); |
||
| 65 | $query->orderBy(['ResultID DESC']); |
||
| 66 | $query->limit(1); |
||
| 67 | |||
| 68 | $statement = $this->db->prepare($query->getStatement()); |
||
| 69 | $statement->execute($query->getBindValues()); |
||
| 70 | |||
| 71 | $row = $statement->fetch(\PDO::FETCH_OBJ); |
||
| 72 | $force = false; |
||
| 73 | |||
| 74 | if (!$this->redis->exists($resultKey)) { |
||
| 75 | $force = true; |
||
| 76 | } else { |
||
| 77 | $lastResult = $this->redis->get($resultKey); |
||
| 78 | if ($lastResult != $row->ResultID) { |
||
| 79 | $force = true; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($force === true) { |
||
| 84 | $output->writeln("Forcing..."); |
||
| 85 | } |
||
| 86 | |||
| 87 | if ($data['lastUpdated'] <= $deadline || $force === true) { |
||
| 88 | $this->update($server, $output); |
||
| 89 | $this->redis->set($resultKey, $row->ResultID); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 105 |