@@ -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 | { |
@@ -342,7 +342,7 @@ |
||
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | if (! in_array($id, $filters)) { |
| 345 | - throw new InvalidArgumentException("Unrecognized {$mode}. Please check the IDs you sent."); |
|
| 345 | + throw new InvalidArgumentException("unrecognized {$mode}. Please check the IDs you sent."); |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
@@ -98,8 +98,6 @@ discard block |
||
| 98 | 98 | * @param string $kind The kind of data we wish to return |
| 99 | 99 | * @param array $data The data itself |
| 100 | 100 | * @param \League\Fractal\TransformerAbstract $callback The transformer class to call |
| 101 | - * @param \Psr\Http\Message\ServerRequestInterface $request The request itself |
|
| 102 | - * @param \Psr\Http\Message\ResponseInterface $response The response object to eventually call |
|
| 103 | 101 | * |
| 104 | 102 | * @return \Psr\Http\Message\ResponseInterface |
| 105 | 103 | */ |
@@ -122,9 +120,8 @@ discard block |
||
| 122 | 120 | * |
| 123 | 121 | * @param array $item The item to transform |
| 124 | 122 | * @param \League\Fractal\TransformerAbstract $transformer The Transformer to pass through to Fractal |
| 125 | - * @param \Psr\Http\Message\ResponseInterface $response The client's response |
|
| 126 | 123 | * |
| 127 | - * @return array |
|
| 124 | + * @return ResponseInterface |
|
| 128 | 125 | */ |
| 129 | 126 | protected function respondWithItem($item, $transformer) |
| 130 | 127 | { |
@@ -152,9 +149,8 @@ discard block |
||
| 152 | 149 | * |
| 153 | 150 | * @param array $collection The collection to transform |
| 154 | 151 | * @param \League\Fractal\TransformerAbstract $transformer The Transformer to pass through to Fractal |
| 155 | - * @param \Psr\Http\Message\ResponseInterface $response The client's response |
|
| 156 | 152 | * |
| 157 | - * @return array |
|
| 153 | + * @return ResponseInterface |
|
| 158 | 154 | */ |
| 159 | 155 | protected function respondWithCollection($collection, $transformer) |
| 160 | 156 | { |
@@ -180,7 +176,6 @@ discard block |
||
| 180 | 176 | /** |
| 181 | 177 | * The final step where the formatted array is now sent back as a response in JSON form |
| 182 | 178 | * |
| 183 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 184 | 179 | * @param array $array |
| 185 | 180 | * |
| 186 | 181 | * @return \Psr\Http\Message\ResponseInterface |
@@ -210,11 +205,10 @@ discard block |
||
| 210 | 205 | /** |
| 211 | 206 | * Responds gracefully with an error. |
| 212 | 207 | * |
| 213 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 214 | 208 | * @param string $message Response message to put in the error |
| 215 | 209 | * @param int $errorCode Error code to set |
| 216 | 210 | * |
| 217 | - * @return array |
|
| 211 | + * @return ResponseInterface |
|
| 218 | 212 | */ |
| 219 | 213 | protected function respondWithError($message, $errorCode) |
| 220 | 214 | { |
@@ -238,10 +232,9 @@ discard block |
||
| 238 | 232 | /** |
| 239 | 233 | * Generates a response with a 404 HTTP error and a given message. |
| 240 | 234 | * |
| 241 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 242 | 235 | * @param string $message |
| 243 | 236 | * |
| 244 | - * @return void |
|
| 237 | + * @return ResponseInterface |
|
| 245 | 238 | */ |
| 246 | 239 | public function errorEmpty($message = 'No data / Empty') |
| 247 | 240 | { |
@@ -252,10 +245,9 @@ discard block |
||
| 252 | 245 | /** |
| 253 | 246 | * Generates a Response with a 403 HTTP header and a given message. |
| 254 | 247 | * |
| 255 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 256 | 248 | * @param string $message |
| 257 | 249 | * |
| 258 | - * @return void |
|
| 250 | + * @return ResponseInterface |
|
| 259 | 251 | */ |
| 260 | 252 | public function errorForbidden($message = 'Forbidden') |
| 261 | 253 | { |
@@ -266,10 +258,9 @@ discard block |
||
| 266 | 258 | /** |
| 267 | 259 | * Generates a Response with a 500 HTTP header and a given message. |
| 268 | 260 | * |
| 269 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 270 | 261 | * @param string $message |
| 271 | 262 | * |
| 272 | - * @return void |
|
| 263 | + * @return ResponseInterface |
|
| 273 | 264 | */ |
| 274 | 265 | public function errorInternalError($message = 'Internal Error') |
| 275 | 266 | { |
@@ -280,10 +271,9 @@ discard block |
||
| 280 | 271 | /** |
| 281 | 272 | * Generates a Response with a 404 HTTP header and a given message. |
| 282 | 273 | * |
| 283 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 284 | 274 | * @param string $message |
| 285 | 275 | * |
| 286 | - * @return void |
|
| 276 | + * @return ResponseInterface |
|
| 287 | 277 | */ |
| 288 | 278 | public function errorNotFound($message = 'Resource Not Found') |
| 289 | 279 | { |
@@ -294,10 +284,9 @@ discard block |
||
| 294 | 284 | /** |
| 295 | 285 | * Generates a Response with a 401 HTTP header and a given message. |
| 296 | 286 | * |
| 297 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 298 | 287 | * @param string $message |
| 299 | 288 | * |
| 300 | - * @return void |
|
| 289 | + * @return ResponseInterface |
|
| 301 | 290 | */ |
| 302 | 291 | public function errorUnauthorized($message = 'Unauthorized') |
| 303 | 292 | { |
@@ -308,7 +297,6 @@ discard block |
||
| 308 | 297 | /** |
| 309 | 298 | * Generates a Response with a 400 HTTP header and a given message. |
| 310 | 299 | * |
| 311 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 312 | 300 | * @param string $message |
| 313 | 301 | * |
| 314 | 302 | * @return \Psr\Http\Message\ResponseInterface |
@@ -322,7 +310,6 @@ discard block |
||
| 322 | 310 | /** |
| 323 | 311 | * Reads any requested includes and adds them to the item / collection |
| 324 | 312 | * |
| 325 | - * @param Psr\Http\Message\ServerRequestInterface $request |
|
| 326 | 313 | * |
| 327 | 314 | * @return void |
| 328 | 315 | */ |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | */ |
| 329 | 329 | public function getIncludesFromRequest() |
| 330 | 330 | { |
| 331 | - if (! empty($_GET['embed'])) { |
|
| 331 | + if (!empty($_GET['embed'])) { |
|
| 332 | 332 | $this->fractal->parseIncludes($_GET['embed']); |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | throw new \Exception(); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - if (! $time) { |
|
| 411 | + if (!$time) { |
|
| 412 | 412 | $time = 3600 * 24; // 1 day |
| 413 | 413 | } |
| 414 | 414 | |
@@ -432,14 +432,14 @@ discard block |
||
| 432 | 432 | $numericals = ['servers', 'zones']; |
| 433 | 433 | $strings = ['factions', 'brackets']; |
| 434 | 434 | |
| 435 | - if (! empty($queryString)) { |
|
| 435 | + if (!empty($queryString)) { |
|
| 436 | 436 | $check = explode(',', $queryString); |
| 437 | 437 | |
| 438 | 438 | // Run a check on the IDs provided to make sure they're valid and no naughty things are being passed |
| 439 | 439 | foreach ($check as $id) { |
| 440 | 440 | // If the query string should contain only numbers |
| 441 | 441 | if (in_array($mode, $numericals)) { |
| 442 | - if (! is_numeric($id)) { |
|
| 442 | + if (!is_numeric($id)) { |
|
| 443 | 443 | throw new InvalidArgumentException("Non numerical ID detected. Only numerical IDs are accepted with this request."); |
| 444 | 444 | } |
| 445 | 445 | } |
@@ -449,14 +449,14 @@ discard block |
||
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | - if (! in_array($id, $filters)) { |
|
| 452 | + if (!in_array($id, $filters)) { |
|
| 453 | 453 | throw new InvalidArgumentException("Unrecognized {$mode}. Please check the IDs you sent."); |
| 454 | 454 | } |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | // Format into strings comma seperated for SQL |
| 458 | 458 | if (in_array($mode, $strings)) { |
| 459 | - $queryString = "'" . implode("','", $check) . "'"; |
|
| 459 | + $queryString = "'".implode("','", $check)."'"; |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | return $queryString; |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | $return = implode(',', $filters); |
| 466 | 466 | |
| 467 | 467 | if (in_array($mode, $strings)) { |
| 468 | - $return = "'" . implode("','", $filters) . "'"; |
|
| 468 | + $return = "'".implode("','", $filters)."'"; |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | // If no string was provided, returns all data encoded as a comma seperated string |
@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * Execution |
| 34 | 34 | * |
| 35 | - * @param Symfony\Component\Console\Input\InputInterface $input |
|
| 36 | - * @param Symfony\Component\Console\Output\OutputInterface $output |
|
| 35 | + * @param InputInterface $input |
|
| 36 | + * @param OutputInterface $output |
|
| 37 | 37 | * |
| 38 | 38 | * @return void |
| 39 | 39 | */ |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * Checks for alerts to be archived then runs routing against said alerts |
| 49 | 49 | * |
| 50 | - * @param Symfony\Component\Console\Output\OutputInterface $output |
|
| 50 | + * @param OutputInterface $output |
|
| 51 | 51 | * |
| 52 | 52 | * @return void |
| 53 | 53 | */ |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | * Execution of routine |
| 122 | 122 | * |
| 123 | 123 | * @param array $alert |
| 124 | - * @param array $tables |
|
| 125 | - * @param Symfony\Component\Console\Output\OutputInterface $output |
|
| 124 | + * @param string[] $tables |
|
| 125 | + * @param OutputInterface $output |
|
| 126 | 126 | * |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
@@ -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 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $alerts = $this->alertRepo->fireStatementAndReturn($query); |
| 73 | 73 | $count = count($alerts); |
| 74 | 74 | |
| 75 | - $output->writeln("Detected {$count} alerts to be archived"); |
|
| 75 | + $output->writeln("detected {$count} alerts to be archived"); |
|
| 76 | 76 | |
| 77 | 77 | if ($count > 0) { |
| 78 | 78 | $tables = [ |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | ['json' => $payload ] |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | - $output->writeln("Archived {$records} records!"); |
|
| 117 | + $output->writeln("archived {$records} records!"); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $this->recordsArchived += $stm->rowCount(); |
| 184 | 184 | $records += $stm->rowCount(); |
| 185 | 185 | |
| 186 | - $output->writeln("Archived {$stm->rowCount()} from Alert #{$alert['ResultID']} - Table {$table}"); |
|
| 186 | + $output->writeln("archived {$stm->rowCount()} from Alert #{$alert['ResultID']} - Table {$table}"); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $this->db->commit(); |
@@ -89,6 +89,10 @@ |
||
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | + /** |
|
| 93 | + * @param integer $server |
|
| 94 | + * @param OutputInterface $output |
|
| 95 | + */ |
|
| 92 | 96 | public function update($server, $output) { |
| 93 | 97 | $output->writeln("Executing update for server: {$server}"); |
| 94 | 98 | |
@@ -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); |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | $data = json_decode($this->redis->get($key), true); |
| 50 | 50 | |
| 51 | 51 | if ($data['beingUpdated'] == 1) { |
| 52 | - $output->writeln("Server {$server} is currently being updated. Deferring."); |
|
| 52 | + $output->writeln("server {$server} is currently being updated. Deferring."); |
|
| 53 | 53 | continue; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -120,6 +120,10 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | + /** |
|
| 124 | + * @param string $metric |
|
| 125 | + * @param integer $server |
|
| 126 | + */ |
|
| 123 | 127 | public function markAsBeingUpdated($metric, $server) |
| 124 | 128 | { |
| 125 | 129 | $key = "ps2alerts:api:leaderboards:status:{$metric}:{$server}"; |
@@ -139,6 +143,10 @@ discard block |
||
| 139 | 143 | $this->redis->set($key, json_encode($data)); |
| 140 | 144 | } |
| 141 | 145 | |
| 146 | + /** |
|
| 147 | + * @param string $metric |
|
| 148 | + * @param integer $server |
|
| 149 | + */ |
|
| 142 | 150 | public function markAsComplete($metric, $server) |
| 143 | 151 | { |
| 144 | 152 | $key = "ps2alerts:api:leaderboards:status:{$metric}:{$server}"; |
@@ -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 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $this->playerLeaderboards($output); |
| 30 | 30 | |
| 31 | 31 | $end = microtime(true); |
| 32 | - $output->writeln("Processing took " . gmdate("H:i:s", ($end - $start))); |
|
| 32 | + $output->writeln("Processing took ".gmdate("H:i:s", ($end - $start))); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function playerLeaderboards(OutputInterface $output) |
@@ -41,16 +41,16 @@ discard block |
||
| 41 | 41 | 'playerSuicides', |
| 42 | 42 | 'headshots' |
| 43 | 43 | ]; |
| 44 | - $servers = [0,1,10,13,17,25,1000,2000]; |
|
| 44 | + $servers = [0, 1, 10, 13, 17, 25, 1000, 2000]; |
|
| 45 | 45 | |
| 46 | - foreach($servers as $server) { |
|
| 47 | - foreach($metrics as $metric) { |
|
| 46 | + foreach ($servers as $server) { |
|
| 47 | + foreach ($metrics as $metric) { |
|
| 48 | 48 | $this->markAsBeingUpdated($metric, $server); |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - foreach($servers as $server) { |
|
| 53 | - foreach($metrics as $metric) { |
|
| 52 | + foreach ($servers as $server) { |
|
| 53 | + foreach ($metrics as $metric) { |
|
| 54 | 54 | $count = 0; |
| 55 | 55 | $limit = 10000; |
| 56 | 56 | $ladderLimit = 10000; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $query->where('playerServer', $server); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - $query->orderBy([$metric . ' DESC']); |
|
| 81 | + $query->orderBy([$metric.' DESC']); |
|
| 82 | 82 | $query->limit($limit); |
| 83 | 83 | $query->offset($count); |
| 84 | 84 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $playerPosKey = "ps2alerts:api:leaderboards:players:pos:{$player->playerID}"; |
| 94 | 94 | |
| 95 | 95 | // If player record doesn't exist |
| 96 | - if (! $this->redis->exists($playerPosKey)) { |
|
| 96 | + if (!$this->redis->exists($playerPosKey)) { |
|
| 97 | 97 | $data = [ |
| 98 | 98 | 'id' => $player->playerID, |
| 99 | 99 | 'updated' => date('U', strtotime('now')) |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // For first time running |
| 106 | - if (! empty($data[$server][$metric])) { |
|
| 106 | + if (!empty($data[$server][$metric])) { |
|
| 107 | 107 | $data[$server][$metric]['old'] = $data[$server][$metric]['new']; |
| 108 | 108 | } else { |
| 109 | 109 | $data[$server][$metric]['old'] = 0; |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | $key = "ps2alerts:api:leaderboards:status:{$metric}:{$server}"; |
| 130 | 130 | |
| 131 | 131 | // Create the key if it doesn't exist for some reason (1st runs) |
| 132 | - if (! $this->redis->exists($key)) { |
|
| 132 | + if (!$this->redis->exists($key)) { |
|
| 133 | 133 | $data = [ |
| 134 | 134 | 'beingUpdated' => 1, |
| 135 | 135 | 'lastUpdated' => 'never' |
@@ -184,6 +184,9 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | + /** |
|
| 188 | + * @param string $metric |
|
| 189 | + */ |
|
| 187 | 190 | public function markAsBeingUpdated($metric, $server) |
| 188 | 191 | { |
| 189 | 192 | $key = "ps2alerts:api:leaderboards:status:{$server}"; |
@@ -205,6 +208,9 @@ discard block |
||
| 205 | 208 | $this->redis->set($key, json_encode($data)); |
| 206 | 209 | } |
| 207 | 210 | |
| 211 | + /** |
|
| 212 | + * @param string $metric |
|
| 213 | + */ |
|
| 208 | 214 | public function markMetricAsComplete($metric, $server) |
| 209 | 215 | { |
| 210 | 216 | $key = "ps2alerts:api:leaderboards:status:{$server}"; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $this->playerLeaderboards($input, $output); |
| 32 | 32 | |
| 33 | 33 | $end = microtime(true); |
| 34 | - $output->writeln("Processing took " . gmdate("H:i:s", ($end - $start))); |
|
| 34 | + $output->writeln("Processing took ".gmdate("H:i:s", ($end - $start))); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function playerLeaderboards(InputInterface $input, OutputInterface $output) |
@@ -47,19 +47,19 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | // Allows server 0, meaning all servers but not to process every server |
| 49 | 49 | if ($serverArg === 'all') { |
| 50 | - $servers = [0,1,10,13,17,25,1000,2000]; |
|
| 50 | + $servers = [0, 1, 10, 13, 17, 25, 1000, 2000]; |
|
| 51 | 51 | } else { |
| 52 | 52 | $servers = [$serverArg]; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - foreach($servers as $server) { |
|
| 56 | - foreach($metrics as $metric) { |
|
| 55 | + foreach ($servers as $server) { |
|
| 56 | + foreach ($metrics as $metric) { |
|
| 57 | 57 | $this->markAsBeingUpdated($metric, $server); |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - foreach($servers as $server) { |
|
| 62 | - foreach($metrics as $metric) { |
|
| 61 | + foreach ($servers as $server) { |
|
| 62 | + foreach ($metrics as $metric) { |
|
| 63 | 63 | $count = 0; |
| 64 | 64 | $limit = 10000; |
| 65 | 65 | $ladderLimit = 10000; |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | if ($server != 0) { |
| 90 | 90 | $query->where("playerServer = ?", $server); |
| 91 | 91 | } |
| 92 | - $query->orderBy([$metric . ' DESC']); |
|
| 92 | + $query->orderBy([$metric.' DESC']); |
|
| 93 | 93 | $query->limit($limit); |
| 94 | 94 | $query->offset($count); |
| 95 | 95 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $playerPosKey = "ps2alerts:api:leaderboards:players:pos:{$player->playerID}"; |
| 105 | 105 | |
| 106 | 106 | // If player record doesn't exist |
| 107 | - if (! $this->redis->exists($playerPosKey)) { |
|
| 107 | + if (!$this->redis->exists($playerPosKey)) { |
|
| 108 | 108 | $data = [ |
| 109 | 109 | 'updated' => [ |
| 110 | 110 | 'daily' => date('U'), |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | 'monthly' |
| 123 | 123 | ]; |
| 124 | 124 | |
| 125 | - foreach($deadlines as $deadline) { |
|
| 125 | + foreach ($deadlines as $deadline) { |
|
| 126 | 126 | // Create the array if empty |
| 127 | 127 | if (empty($data[$server][$metric][$deadline])) { |
| 128 | 128 | $data[$server][$metric][$deadline] = []; |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // Flip new to old |
| 141 | - if (! empty($row)) { |
|
| 141 | + if (!empty($row)) { |
|
| 142 | 142 | $row['old']['pos'] = $row['new']['pos']; |
| 143 | 143 | $row['old']['val'] = $row['new']['val']; |
| 144 | 144 | } |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $key = "ps2alerts:api:leaderboards:status:{$server}"; |
| 190 | 190 | |
| 191 | 191 | // Create the key if it doesn't exist for some reason (1st runs) |
| 192 | - if (! $this->redis->exists($key)) { |
|
| 192 | + if (!$this->redis->exists($key)) { |
|
| 193 | 193 | $data = [ |
| 194 | 194 | 'beingUpdated' => 1, |
| 195 | 195 | 'lastUpdated' => date('U'), |
@@ -89,7 +89,7 @@ |
||
| 89 | 89 | $query->cols(['*']); |
| 90 | 90 | $query->from('ws_players_total'); |
| 91 | 91 | if ($server != 0) { |
| 92 | - $query->where("playerServer = ?", $server); |
|
| 92 | + $query->where("playerServer = ?", $server); |
|
| 93 | 93 | } |
| 94 | 94 | $query->orderBy([$metric . ' DESC']); |
| 95 | 95 | $query->limit($limit); |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * Set the http message request |
| 22 | 22 | * |
| 23 | - * @param \Zend\Diactoros\ServerRequestFactory $obj |
|
| 23 | + * @param ServerRequest $obj |
|
| 24 | 24 | */ |
| 25 | 25 | public function setRequest(ServerRequest $obj) |
| 26 | 26 | { |
@@ -30,7 +30,6 @@ discard block |
||
| 30 | 30 | /** |
| 31 | 31 | * Getthe http message request |
| 32 | 32 | * |
| 33 | - * @param \Zend\Diactoros\ServerRequestFactory $obj |
|
| 34 | 33 | */ |
| 35 | 34 | public function getRequest() |
| 36 | 35 | { |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Retrieves combat totals on a global and per-server basis |
| 25 | 25 | * @param ServerRequestInterface $request |
| 26 | 26 | * @param ResponseInterface $response |
| 27 | - * @return array |
|
| 27 | + * @return ResponseInterface |
|
| 28 | 28 | */ |
| 29 | 29 | public function getCombatTotals(ServerRequestInterface $request, ResponseInterface $response) |
| 30 | 30 | { |
@@ -250,6 +250,9 @@ discard block |
||
| 250 | 250 | return $this->respondWithArray($results); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | + /** |
|
| 254 | + * @param integer $classID |
|
| 255 | + */ |
|
| 253 | 256 | private function findClassGrouping($classID) |
| 254 | 257 | { |
| 255 | 258 | $classGroups = $this->getConfig()['classesGroups']; |
@@ -265,6 +268,9 @@ discard block |
||
| 265 | 268 | return false; |
| 266 | 269 | } |
| 267 | 270 | |
| 271 | + /** |
|
| 272 | + * @param integer $classID |
|
| 273 | + */ |
|
| 268 | 274 | private function findClassFaction($classID) |
| 269 | 275 | { |
| 270 | 276 | $classesFactions = $this->getConfig()['classesFactions']; |
@@ -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; |