| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | */ | 
| 20 | 20 | public function register() | 
| 21 | 21 |      { | 
| 22 | -        $this->getContainer()->add('Ramsey\Uuid\Uuid', function () { | |
| 22 | +        $this->getContainer()->add('Ramsey\Uuid\Uuid', function() { | |
| 23 | 23 | $uuid = Uuid::Uuid4(); | 
| 24 | 24 | return $uuid; | 
| 25 | 25 | }); | 
| @@ -1,8 +1,6 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | 3 | use GuzzleHttp\Client; | 
| 4 | -use GuzzleHttp\Psr7\Request; | |
| 5 | -use GuzzleHttp\Psr7\Response; | |
| 6 | 4 | |
| 7 | 5 | class AlertControllerTest extends \PHPUnit_Framework_TestCase | 
| 8 | 6 |  { | 
| @@ -7,7 +7,6 @@ | ||
| 7 | 7 | use Symfony\Component\Console\Command\Command; | 
| 8 | 8 | use Symfony\Component\Console\Input\InputArgument; | 
| 9 | 9 | use Symfony\Component\Console\Input\InputInterface; | 
| 10 | -use Symfony\Component\Console\Input\InputOption; | |
| 11 | 10 | use Symfony\Component\Console\Output\OutputInterface; | 
| 12 | 11 | |
| 13 | 12 | class ArchiveCommand extends BaseCommand | 
| @@ -61,11 +61,11 @@ discard block | ||
| 61 | 61 |          $query->where('ResultStartTime < ?', $obj->format('U')); | 
| 62 | 62 |          $query->where('Archived = 0'); | 
| 63 | 63 | |
| 64 | -        if (! empty($input->getArgument('start'))) { | |
| 64 | +        if (!empty($input->getArgument('start'))) { | |
| 65 | 65 |              $query->where('ResultID >= ?', $input->getArgument('start')); | 
| 66 | 66 | } | 
| 67 | 67 | |
| 68 | -        if (! empty($input->getArgument('process'))) { | |
| 68 | +        if (!empty($input->getArgument('process'))) { | |
| 69 | 69 |              $query->where('ResultID <= ?', $input->getArgument('process')); | 
| 70 | 70 | } | 
| 71 | 71 | |
| @@ -90,7 +90,7 @@ discard block | ||
| 90 | 90 | 'ws_xp' | 
| 91 | 91 | ]; | 
| 92 | 92 | |
| 93 | -            for ($i=0; $i < $count; $i++) { | |
| 93 | +            for ($i = 0; $i < $count; $i++) { | |
| 94 | 94 | $this->archive($alerts[$i], $tables, $output); | 
| 95 | 95 | |
| 96 | 96 | $per = ($i / $count) * 100; | 
| @@ -111,7 +111,7 @@ discard block | ||
| 111 | 111 | $this->guzzle->request( | 
| 112 | 112 | 'POST', | 
| 113 | 113 | 'https://hooks.slack.com/services/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', | 
| 114 | - ['json' => $payload ] | |
| 114 | + ['json' => $payload] | |
| 115 | 115 | ); | 
| 116 | 116 | |
| 117 | 117 |          $output->writeln("Archived {$records} records!"); | 
| @@ -133,7 +133,7 @@ discard block | ||
| 133 | 133 | $this->dbArchive->beginTransaction(); | 
| 134 | 134 | |
| 135 | 135 | // Get all data and insert it into the archive DB | 
| 136 | -        foreach($tables as $table) { | |
| 136 | +        foreach ($tables as $table) { | |
| 137 | 137 |              $output->writeln("Alert #{$alert['ResultID']} - Table: {$table}"); | 
| 138 | 138 | |
| 139 | 139 |              $sql = "SELECT * FROM {$table} WHERE resultID = :result"; | 
| @@ -155,7 +155,7 @@ discard block | ||
| 155 | 155 | } | 
| 156 | 156 | |
| 157 | 157 | $values = rtrim($values, ','); | 
| 158 | -                $sql  = "INSERT INTO {$table} ({$cols}) VALUES {$values}"; | |
| 158 | +                $sql = "INSERT INTO {$table} ({$cols}) VALUES {$values}"; | |
| 159 | 159 | |
| 160 | 160 | $this->dbArchive->exec($sql); | 
| 161 | 161 | } | 
| @@ -175,7 +175,7 @@ discard block | ||
| 175 | 175 | $this->db->beginTransaction(); | 
| 176 | 176 | |
| 177 | 177 | // Loop through all tables and delete the alert's data from the DB | 
| 178 | -        foreach($tables as $table) { | |
| 178 | +        foreach ($tables as $table) { | |
| 179 | 179 |              $sql = "DELETE FROM {$table} WHERE resultID = :result"; | 
| 180 | 180 | $stm = $this->db->prepare($sql); | 
| 181 | 181 | $stm->execute(['result' => $alert['ResultID']]); | 
| @@ -207,7 +207,7 @@ discard block | ||
| 207 | 207 | public function buildCols($row) | 
| 208 | 208 |      { | 
| 209 | 209 | $keys = []; | 
| 210 | -        foreach($row as $key => $val) { | |
| 210 | +        foreach ($row as $key => $val) { | |
| 211 | 211 | $keys[] = (string) $key; | 
| 212 | 212 | } | 
| 213 | 213 | |
| @@ -224,7 +224,7 @@ discard block | ||
| 224 | 224 | public function buildValues($row) | 
| 225 | 225 |      { | 
| 226 | 226 | $values = []; | 
| 227 | -        foreach($row as $key => $val) { | |
| 227 | +        foreach ($row as $key => $val) { | |
| 228 | 228 |              $val = str_replace("'", '', $val); // Remove any apostophies from char names | 
| 229 | 229 | $values[] = $val; | 
| 230 | 230 | } | 
| @@ -3,7 +3,6 @@ | ||
| 3 | 3 | namespace Ps2alerts\Api\Command; | 
| 4 | 4 | |
| 5 | 5 | use Ps2alerts\Api\Command\BaseCommand; | 
| 6 | -use Symfony\Component\Console\Input\InputArgument; | |
| 7 | 6 | use Symfony\Component\Console\Input\InputInterface; | 
| 8 | 7 | use Symfony\Component\Console\Output\OutputInterface; | 
| 9 | 8 | |
| @@ -34,13 +34,13 @@ discard block | ||
| 34 | 34 | $servers = $this->config['servers']; | 
| 35 | 35 | $servers[] = 0; | 
| 36 | 36 | |
| 37 | -        foreach($servers as $server) { | |
| 37 | +        foreach ($servers as $server) { | |
| 38 | 38 |              $output->writeln("Checking Server {$server}"); | 
| 39 | 39 | |
| 40 | 40 |              $key = "ps2alerts:api:leaderboards:status:{$server}"; | 
| 41 | 41 |              $resultKey = "ps2alerts:api:leaderboards:lastResult:{$server}"; | 
| 42 | 42 | |
| 43 | -            if (! $this->redis->exists($key)) { | |
| 43 | +            if (!$this->redis->exists($key)) { | |
| 44 | 44 |                  $output->writeln("Key doesn't exist for server {$server}! Forcing!"); | 
| 45 | 45 | $this->update($server, $output); | 
| 46 | 46 | continue; | 
| @@ -69,7 +69,7 @@ discard block | ||
| 69 | 69 | $row = $statement->fetch(\PDO::FETCH_OBJ); | 
| 70 | 70 | $force = false; | 
| 71 | 71 | |
| 72 | -            if (! $this->redis->exists($resultKey)) { | |
| 72 | +            if (!$this->redis->exists($resultKey)) { | |
| 73 | 73 | $force = true; | 
| 74 | 74 |              } else { | 
| 75 | 75 | $lastResult = $this->redis->get($resultKey); | 
| @@ -2,11 +2,8 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Ps2alerts\Api\Controller\Endpoint\Alerts; | 
| 4 | 4 | |
| 5 | -use League\Fractal\Manager; | |
| 6 | 5 | use Ps2alerts\Api\Controller\Endpoint\Alerts\AlertEndpointController; | 
| 7 | 6 | use Ps2alerts\Api\Exception\InvalidArgumentException; | 
| 8 | -use Ps2alerts\Api\Repository\Metrics\CombatRepository; | |
| 9 | -use Ps2alerts\Api\Repository\Metrics\ClassRepository; | |
| 10 | 7 | use Psr\Http\Message\ServerRequestInterface; | 
| 11 | 8 | use Psr\Http\Message\ResponseInterface; | 
| 12 | 9 | |
| @@ -49,23 +49,23 @@ discard block | ||
| 49 | 49 |              $data = $this->checkRedis('api', 'combatTotals', "{$server}-data"); | 
| 50 | 50 |              $dataArchive = $this->checkRedis('api', 'combatTotals', "{$server}-dataArchive"); | 
| 51 | 51 | |
| 52 | -            if (! $data || ! $dataArchive) { | |
| 52 | +            if (!$data || !$dataArchive) { | |
| 53 | 53 | $sums = []; | 
| 54 | 54 |                  foreach ($metrics as $metric) { | 
| 55 | 55 |                      foreach ($factions as $faction) { | 
| 56 | - $dbMetric = $metric . strtoupper($faction); // e.g. killsVS | |
| 57 | - $dataMetric = $metric . strtoupper($faction); // e.g. killsVS | |
| 56 | + $dbMetric = $metric.strtoupper($faction); // e.g. killsVS | |
| 57 | + $dataMetric = $metric.strtoupper($faction); // e.g. killsVS | |
| 58 | 58 | |
| 59 | 59 | // Handle teamkills inconsistency | 
| 60 | 60 |                          if ($metric === 'teamkills') { | 
| 61 | - $dbMetric = 'teamKills' . strtoupper($faction); | |
| 61 | + $dbMetric = 'teamKills'.strtoupper($faction); | |
| 62 | 62 | } | 
| 63 | 63 |                          $sums[] = "SUM(factions.{$dbMetric}) AS $dataMetric"; | 
| 64 | 64 | } | 
| 65 | 65 | |
| 66 | 66 | // Totals | 
| 67 | - $dbMetric = 'total' . ucfirst($metric); // e.g. killsVS | |
| 68 | - $dataMetric = 'total' . ucfirst($metric); // e.g. killsVS | |
| 67 | + $dbMetric = 'total'.ucfirst($metric); // e.g. killsVS | |
| 68 | + $dataMetric = 'total'.ucfirst($metric); // e.g. killsVS | |
| 69 | 69 | |
| 70 | 70 | // Handle teamkills inconsistency | 
| 71 | 71 |                      if ($metric === 'teamkills') { | 
| @@ -100,12 +100,12 @@ discard block | ||
| 100 | 100 | // Merge the two arrays together | 
| 101 | 101 |              foreach ($metrics as $metric) { | 
| 102 | 102 | // Tot up totals | 
| 103 | - $dbMetric = 'total' . ucfirst($metric); | |
| 103 | + $dbMetric = 'total'.ucfirst($metric); | |
| 104 | 104 | $mergedArray['totals'][$metric] = (int) $data[$dbMetric] + (int) $dataArchive[$dbMetric]; | 
| 105 | 105 | $results['all']['totals'][$metric] += $mergedArray['totals'][$metric]; | 
| 106 | 106 | |
| 107 | 107 |                  foreach ($factions as $faction) { | 
| 108 | - $dbMetric = $metric . strtoupper($faction); | |
| 108 | + $dbMetric = $metric.strtoupper($faction); | |
| 109 | 109 | $mergedArray[$metric][$faction] = (int) $data[$dbMetric] + (int) $dataArchive[$dbMetric]; | 
| 110 | 110 | $results['all'][$metric][$faction] += $mergedArray[$metric][$faction]; | 
| 111 | 111 | } | 
| @@ -148,7 +148,7 @@ discard block | ||
| 148 | 148 |              $dataArchive = $this->checkRedis('api', 'classCombat', "{$server}-dataArchive", 'object'); | 
| 149 | 149 | |
| 150 | 150 | // If data needs a pull | 
| 151 | -            if (! $data || ! $dataArchive) { | |
| 151 | +            if (!$data || !$dataArchive) { | |
| 152 | 152 |                  $query = $this->combatRepository->newQuery('single', true); | 
| 153 | 153 | $query->cols([ | 
| 154 | 154 | 'classID', | 
| @@ -181,8 +181,8 @@ discard block | ||
| 181 | 181 | // Typecase into ints and increase totals | 
| 182 | 182 | $metrics = ['kills', 'deaths', 'teamkills', 'suicides']; | 
| 183 | 183 |              foreach ($data as $row) { | 
| 184 | - $row->classID = (int) $row->classID; | |
| 185 | - $row->server = (int) $row->server; | |
| 184 | + $row->classID = (int) $row->classID; | |
| 185 | + $row->server = (int) $row->server; | |
| 186 | 186 | $classGroup = $this->findClassGrouping($row->classID); | 
| 187 | 187 | $faction = $this->findClassFaction($row->classID); | 
| 188 | 188 | |
| @@ -201,8 +201,8 @@ discard block | ||
| 201 | 201 | } | 
| 202 | 202 | |
| 203 | 203 |              foreach ($dataArchive as $row) { | 
| 204 | - $row->classID = (int) $row->classID; | |
| 205 | - $row->server = (int) $row->server; | |
| 204 | + $row->classID = (int) $row->classID; | |
| 205 | + $row->server = (int) $row->server; | |
| 206 | 206 | |
| 207 | 207 |                  foreach ($metrics as $metric) { | 
| 208 | 208 | $row->$metric = (int) $row->$metric; | 
| @@ -5,7 +5,6 @@ | ||
| 5 | 5 | use League\Fractal\Manager; | 
| 6 | 6 | use Ps2alerts\Api\Controller\Endpoint\AbstractEndpointController; | 
| 7 | 7 | use Ps2alerts\Api\Repository\AlertRepository; | 
| 8 | -use Ps2alerts\Api\Transformer\AlertTotalTransformer; | |
| 9 | 8 | use Ps2alerts\Api\Transformer\AlertTransformer; | 
| 10 | 9 | use Psr\Http\Message\ServerRequestInterface; | 
| 11 | 10 | use Psr\Http\Message\ResponseInterface; | 
| @@ -103,11 +103,11 @@ discard block | ||
| 103 | 103 | $limit = (int) $_GET['limit']; | 
| 104 | 104 | |
| 105 | 105 | // Set defaults if not supplied | 
| 106 | -        if (empty($offset) || ! is_numeric($offset)) { | |
| 106 | +        if (empty($offset) || !is_numeric($offset)) { | |
| 107 | 107 | $offset = 0; | 
| 108 | 108 | } | 
| 109 | 109 | |
| 110 | -        if (empty($limit) || ! is_numeric($limit)) { | |
| 110 | +        if (empty($limit) || !is_numeric($limit)) { | |
| 111 | 111 | $limit = 50; | 
| 112 | 112 | } | 
| 113 | 113 | |
| @@ -173,11 +173,11 @@ discard block | ||
| 173 | 173 | $limit = (int) $_GET['limit']; | 
| 174 | 174 | |
| 175 | 175 | // Set defaults if not supplied | 
| 176 | -        if (empty($offset) || ! is_numeric($offset)) { | |
| 176 | +        if (empty($offset) || !is_numeric($offset)) { | |
| 177 | 177 | $offset = 0; | 
| 178 | 178 | } | 
| 179 | 179 | |
| 180 | -        if (empty($limit) || ! is_numeric($limit)) { | |
| 180 | +        if (empty($limit) || !is_numeric($limit)) { | |
| 181 | 181 | $limit = 50; | 
| 182 | 182 | } | 
| 183 | 183 | |
| @@ -5,10 +5,7 @@ | ||
| 5 | 5 | use League\Fractal\Manager; | 
| 6 | 6 | use Ps2alerts\Api\Controller\Endpoint\AbstractEndpointController; | 
| 7 | 7 | use Ps2alerts\Api\Repository\AlertRepository; | 
| 8 | -use Ps2alerts\Api\Transformer\AlertTotalTransformer; | |
| 9 | 8 | use Ps2alerts\Api\Transformer\AlertTransformer; | 
| 10 | -use Psr\Http\Message\ServerRequestInterface; | |
| 11 | -use Psr\Http\Message\ResponseInterface; | |
| 12 | 9 | |
| 13 | 10 | class ContextualDataEndpointController extends AbstractEndpointController | 
| 14 | 11 |  { | 
| @@ -22,6 +22,6 @@ | ||
| 22 | 22 | public function __construct( | 
| 23 | 23 | Manager $fractal | 
| 24 | 24 |      ) { | 
| 25 | - $this->fractal = $fractal; | |
| 25 | + $this->fractal = $fractal; | |
| 26 | 26 | } | 
| 27 | 27 | } | 
| @@ -11,7 +11,6 @@ | ||
| 11 | 11 | use Ps2alerts\Api\Repository\Metrics\OutfitTotalRepository; | 
| 12 | 12 | use Ps2alerts\Api\Repository\Metrics\PlayerTotalRepository; | 
| 13 | 13 | use Ps2alerts\Api\Repository\Metrics\WeaponTotalRepository; | 
| 14 | -use Ps2alerts\Api\Transformer\Leaderboards\LeaderboardUpdatedTransformer; | |
| 15 | 14 | use Ps2alerts\Api\Transformer\Leaderboards\OutfitLeaderboardTransformer; | 
| 16 | 15 | use Ps2alerts\Api\Transformer\Leaderboards\PlayerLeaderboardTransformer; | 
| 17 | 16 | use Ps2alerts\Api\Transformer\Leaderboards\WeaponLeaderboardTransformer; | 
| @@ -83,7 +83,7 @@ discard block | ||
| 83 | 83 | } | 
| 84 | 84 | } | 
| 85 | 85 | |
| 86 | -        if (! isset($field)) { | |
| 86 | +        if (!isset($field)) { | |
| 87 | 87 |              return $this->errorWrongArgs('Field wasn\'t provided and is required.'); | 
| 88 | 88 | } | 
| 89 | 89 | |
| @@ -112,7 +112,7 @@ discard block | ||
| 112 | 112 | |
| 113 | 113 | // Gets outfit details | 
| 114 | 114 |          for ($i = 0; $i < $count; $i++) { | 
| 115 | -            if (! empty($players[$i]['playerOutfit'])) { | |
| 115 | +            if (!empty($players[$i]['playerOutfit'])) { | |
| 116 | 116 | // Gets outfit details | 
| 117 | 117 |                  try { | 
| 118 | 118 | $outfit = $this->dataEndpoint->getOutfit($players[$i]['playerOutfit']); | 
| @@ -176,7 +176,7 @@ discard block | ||
| 176 | 176 | } | 
| 177 | 177 | } | 
| 178 | 178 | |
| 179 | -        if (! isset($field)) { | |
| 179 | +        if (!isset($field)) { | |
| 180 | 180 |              return $this->errorWrongArgs('Field wasn\'t provided and is required.'); | 
| 181 | 181 | } | 
| 182 | 182 | |
| @@ -239,7 +239,7 @@ discard block | ||
| 239 | 239 | } | 
| 240 | 240 | } | 
| 241 | 241 | |
| 242 | -        if (! isset($field)) { | |
| 242 | +        if (!isset($field)) { | |
| 243 | 243 |              return $this->errorWrongArgs('Field wasn\'t provided and is required.'); | 
| 244 | 244 | } | 
| 245 | 245 | |
| @@ -282,19 +282,19 @@ discard block | ||
| 282 | 282 | public function validateRequestVars($request) | 
| 283 | 283 |      { | 
| 284 | 284 |          try { | 
| 285 | -            if (! empty($_GET['field'])) { | |
| 285 | +            if (!empty($_GET['field'])) { | |
| 286 | 286 | $this->parseField($_GET['field']); | 
| 287 | 287 | } | 
| 288 | 288 | |
| 289 | -            if (! empty($_GET['server'])) { | |
| 289 | +            if (!empty($_GET['server'])) { | |
| 290 | 290 | $this->parseServer($_GET['server']); | 
| 291 | 291 | } | 
| 292 | 292 | |
| 293 | -            if (! empty($_GET['limit'])) { | |
| 293 | +            if (!empty($_GET['limit'])) { | |
| 294 | 294 | $this->parseOffset($_GET['limit']); | 
| 295 | 295 | } | 
| 296 | 296 | |
| 297 | -            if (! empty($_GET['offset'])) { | |
| 297 | +            if (!empty($_GET['offset'])) { | |
| 298 | 298 | $this->parseOffset($_GET['offset']); | 
| 299 | 299 | } | 
| 300 | 300 |          } catch (InvalidArgumentException $e) { | 
| @@ -320,7 +320,7 @@ discard block | ||
| 320 | 320 | 'captures' | 
| 321 | 321 | ]; | 
| 322 | 322 | |
| 323 | -        if (! empty($field) && in_array($field, $validFields)) { | |
| 323 | +        if (!empty($field) && in_array($field, $validFields)) { | |
| 324 | 324 | return $field; | 
| 325 | 325 | } | 
| 326 | 326 | |
| @@ -341,7 +341,7 @@ discard block | ||
| 341 | 341 | unset($validServers[$key]); | 
| 342 | 342 | } | 
| 343 | 343 | |
| 344 | -        if (! empty($server) && in_array($server, $validServers)) { | |
| 344 | +        if (!empty($server) && in_array($server, $validServers)) { | |
| 345 | 345 | return $server; | 
| 346 | 346 | } | 
| 347 | 347 | |
| @@ -355,7 +355,7 @@ discard block | ||
| 355 | 355 | */ | 
| 356 | 356 | public function parseLimit($limit) | 
| 357 | 357 |      { | 
| 358 | -        if (! isset($limit) && ! is_numeric($limit)) { | |
| 358 | +        if (!isset($limit) && !is_numeric($limit)) { | |
| 359 | 359 |              throw new InvalidArgumentException("Limit needs to be in numerical format."); | 
| 360 | 360 | } | 
| 361 | 361 | |
| @@ -367,7 +367,7 @@ discard block | ||
| 367 | 367 | */ | 
| 368 | 368 | public function parseOffset($offset) | 
| 369 | 369 |      { | 
| 370 | -        if (! isset($offset) && ! is_numeric($offset)) { | |
| 370 | +        if (!isset($offset) && !is_numeric($offset)) { | |
| 371 | 371 |              throw new InvalidArgumentException("Offset needs to be in numerical format."); | 
| 372 | 372 | } | 
| 373 | 373 | |
| @@ -2,10 +2,7 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Ps2alerts\Api\Controller\Endpoint\Leaderboards; | 
| 4 | 4 | |
| 5 | -use League\Fractal\Manager; | |
| 6 | 5 | use Ps2alerts\Api\Controller\Endpoint\AbstractEndpointController; | 
| 7 | -use Ps2alerts\Api\Repository\Metrics\OutfitTotalRepository; | |
| 8 | -use Ps2alerts\Api\Repository\Metrics\PlayerTotalRepository; | |
| 9 | 6 | use Psr\Http\Message\ServerRequestInterface; | 
| 10 | 7 | use Psr\Http\Message\ResponseInterface; | 
| 11 | 8 | |
| @@ -83,7 +83,7 @@ | ||
| 83 | 83 | |
| 84 | 84 | $data = []; | 
| 85 | 85 | |
| 86 | -        foreach($config['servers'] as $server) { | |
| 86 | +        foreach ($config['servers'] as $server) { | |
| 87 | 87 |              $key = "ps2alerts:api:leaderboards:status:{$server}"; | 
| 88 | 88 | |
| 89 | 89 |              if ($redis->exists($key)) { |