Passed
Pull Request — master (#35)
by
unknown
01:59
created
src/Shell/Task/QueueTask.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@
 block discarded – undo
66 66
         $class = get_class($this);
67 67
 
68 68
         preg_match('#\\\\Queue(.+)Task$#', $class, $matches);
69
-        if (! $matches) {
69
+        if (!$matches) {
70 70
             throw new InvalidArgumentException('Invalid class name: ' . $class);
71 71
         }
72 72
 
Please login to merge, or discard this patch.
src/Shell/QueueShell.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use Queue\Shell\Task\QueueTaskInterface;
18 18
 use RuntimeException;
19 19
 use Throwable;
20
-declare(ticks = 1);
20
+declare(ticks=1);
21 21
 
22 22
 /**
23 23
  * Main shell to init and run queue workers.
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
         if (in_array('Queue' . $name, $this->taskNames, true)) {
122 122
             /** @var \Queue\Shell\Task\QueueTask|\Queue\Shell\Task\AddInterface $task */
123 123
             $task = $this->{'Queue' . $name};
124
-            if (! ($task instanceof AddInterface)) {
124
+            if (!($task instanceof AddInterface)) {
125 125
                 $this->abort('This task does not support adding via CLI call');
126 126
             }
127 127
             $task->add();
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             $pid = $this->_initPid();
161 161
         } catch (PersistenceFailedException $exception) {
162 162
             $this->err($exception->getMessage());
163
-            $limit = (int) Configure::read('Queue.maxWorkers');
163
+            $limit = (int)Configure::read('Queue.maxWorkers');
164 164
             if ($limit) {
165 165
                 $this->out('Cannot start worker: Too many workers already/still running on this server (' . $limit . '/' . $limit . ')');
166 166
             }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         $startTime = time();
195 195
         $types = $this->_stringToArray($this->param('type'));
196 196
 
197
-        while (! $this->_exit) {
197
+        while (!$this->_exit) {
198 198
             $this->out(__d('queue', 'Looking for a job.'), 1, Shell::VERBOSE);
199 199
 
200 200
             $QueuedTask = $this->QueuedTasks->requestJob($this->_getTaskConf(), $types);
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
                 $this->_exit = true;
215 215
                 $this->out('queue', 'Reached runtime of ' . (time() - $startTime) . ' Seconds (Max ' . Configure::readOrFail('Queue.workerMaxRuntime') . '), terminating.');
216 216
             }
217
-            if ($this->_exit || mt_rand(0, 100) > (100 - (int) Config::gcprob())) {
217
+            if ($this->_exit || mt_rand(0, 100) > (100 - (int)Config::gcprob())) {
218 218
                 $this->out(__d('queue', 'Performing old job cleanup.'));
219 219
                 $this->QueuedTasks->cleanOldJobs();
220 220
             }
@@ -246,11 +246,11 @@  discard block
 block discarded – undo
246 246
             $data = unserialize($QueuedTask->data);
247 247
             /** @var \Queue\Shell\Task\QueueTask $task */
248 248
             $task = $this->{$taskName};
249
-            if (! $task instanceof QueueTaskInterface) {
249
+            if (!$task instanceof QueueTaskInterface) {
250 250
                 throw new RuntimeException('Task must implement ' . QueueTaskInterface::class);
251 251
             }
252 252
 
253
-            $return = $task->run((array) $data, $QueuedTask->id);
253
+            $return = $task->run((array)$data, $QueuedTask->id);
254 254
             if ($return !== null) {
255 255
                 trigger_error('run() should be void and throw exception in error case now.', E_USER_DEPRECATED);
256 256
             }
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
             $return = false;
260 260
 
261 261
             $failureMessage = get_class($e) . ': ' . $e->getMessage();
262
-            if (! ($e instanceof QueueException)) {
262
+            if (!($e instanceof QueueException)) {
263 263
                 $failureMessage .= "\n" . $e->getTraceAsString();
264 264
             }
265 265
 
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
      */
291 291
     public function clean()
292 292
     {
293
-        if (! Configure::read('Queue.cleanupTimeout')) {
293
+        if (!Configure::read('Queue.cleanupTimeout')) {
294 294
             $this->abort('You disabled cleanuptimout in config. Aborting.');
295 295
         }
296 296
 
297
-        $this->out('Deleting old jobs, that have finished before ' . date('Y-m-d H:i:s', time() - (int) Configure::read('Queue.cleanupTimeout')));
297
+        $this->out('Deleting old jobs, that have finished before ' . date('Y-m-d H:i:s', time() - (int)Configure::read('Queue.cleanupTimeout')));
298 298
         $this->QueuedTasks->cleanOldJobs();
299 299
     }
300 300
 
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
     public function settings()
307 307
     {
308 308
         $this->out('Current Settings:');
309
-        $conf = (array) Configure::read('Queue');
309
+        $conf = (array)Configure::read('Queue');
310 310
         foreach ($conf as $key => $val) {
311 311
             if ($val === false) {
312 312
                 $val = 'no';
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
     public function getOptionParser()
356 356
     {
357 357
         $subcommandParser = [
358
-            'options' => [ /*
358
+            'options' => [/*
359 359
                              * 'dry-run'=> array(
360 360
                              * 'short' => 'd',
361 361
                              * 'help' => 'Dry run the update, no jobs will actually be added.',
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
      */
407 407
     protected function _log($message, $pid = null, $addDetails = true)
408 408
     {
409
-        if (! Configure::read('Queue.log')) {
409
+        if (!Configure::read('Queue.log')) {
410 410
             return;
411 411
         }
412 412
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
      */
452 452
     protected function _getTaskConf()
453 453
     {
454
-        if (! is_array($this->_taskConf)) {
454
+        if (!is_array($this->_taskConf)) {
455 455
             $this->_taskConf = [];
456 456
             foreach ($this->tasks as $task) {
457 457
                 list ($pluginName, $taskName) = pluginSplit($task);
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
     protected function _retrievePid()
520 520
     {
521 521
         if (function_exists('posix_getpid')) {
522
-            $pid = (string) posix_getpid();
522
+            $pid = (string)posix_getpid();
523 523
         } else {
524 524
             $pid = $this->QueuedTasks->key();
525 525
         }
@@ -550,10 +550,10 @@  discard block
 block discarded – undo
550 550
      */
551 551
     protected function _deletePid($pid)
552 552
     {
553
-        if (! $pid) {
553
+        if (!$pid) {
554 554
             $pid = $this->_pid;
555 555
         }
556
-        if (! $pid) {
556
+        if (!$pid) {
557 557
             return;
558 558
         }
559 559
     }
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
      */
593 593
     protected function _stringToArray($param)
594 594
     {
595
-        if (! $param) {
595
+        if (!$param) {
596 596
             return [];
597 597
         }
598 598
 
Please login to merge, or discard this patch.
src/Model/Table/QueuedTasksTable.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     public static function defaultConnectionName()
69 69
     {
70 70
         $connection = Configure::read('Queue.connection');
71
-        if (! empty($connection)) {
71
+        if (!empty($connection)) {
72 72
             return $connection;
73 73
         }
74 74
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
             'not_before' => $this->getDateTime()
109 109
         ];
110 110
 
111
-        if (! empty($notBefore)) {
111
+        if (!empty($notBefore)) {
112 112
             $task['not_before'] = $this->getDateTime(strtotime($notBefore));
113 113
         }
114 114
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
             $conditions['task'] = $taskName;
135 135
         }
136 136
 
137
-        return (bool) $this->find()
137
+        return (bool)$this->find()
138 138
             ->where($conditions)
139 139
             ->select([
140 140
             'id'
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
     {
195 195
         $driverName = $this->_getDriverName();
196 196
         $options = [
197
-            'fields' => function (Query $query) use ($driverName) {
197
+            'fields' => function(Query $query) use ($driverName) {
198 198
                 $alltime = $query->func()->avg('UNIX_TIMESTAMP(completed) - UNIX_TIMESTAMP(created)');
199 199
                 $runtime = $query->func()->avg('UNIX_TIMESTAMP(completed) - UNIX_TIMESTAMP(fetched)');
200 200
                 $fetchdelay = $query->func()->avg('UNIX_TIMESTAMP(fetched) - IF(not_before is NULL, UNIX_TIMESTAMP(created), UNIX_TIMESTAMP(not_before))');
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
     public function getFullStats($taskName = null)
242 242
     {
243 243
         $driverName = $this->_getDriverName();
244
-        $fields = function (Query $query) use ($driverName) {
244
+        $fields = function(Query $query) use ($driverName) {
245 245
             $runtime = $query->newExpr('UNIX_TIMESTAMP(completed) - UNIX_TIMESTAMP(fetched)');
246 246
             switch ($driverName) {
247 247
                 case static::DRIVER_SQLSERVER:
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
             /** @var \DateTime $created */
281 281
             $created = $task['created'];
282 282
             $day = $created->format('Y-m-d');
283
-            if (! isset($days[$day])) {
283
+            if (!isset($days[$day])) {
284 284
                 $days[$day] = $day;
285 285
             }
286 286
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
         foreach ($result as $type => $tasks) {
291 291
             foreach ($tasks as $day => $durations) {
292 292
                 $average = array_sum($durations) / count($durations);
293
-                $result[$type][$day] = (int) $average;
293
+                $result[$type][$day] = (int)$average;
294 294
             }
295 295
 
296 296
             foreach ($days as $day) {
@@ -377,13 +377,13 @@  discard block
 block discarded – undo
377 377
         }
378 378
 
379 379
         /** @var \Queue\Model\Entity\QueuedTask|null $task */
380
-        $task = $this->getConnection()->transactional(function () use ($query, $options, $now) {
380
+        $task = $this->getConnection()->transactional(function() use ($query, $options, $now) {
381 381
             $task = $query->find('all', $options)
382 382
                 ->enableAutoFields(true)
383 383
                 ->epilog('FOR UPDATE')
384 384
                 ->first();
385 385
 
386
-            if (! $task) {
386
+            if (!$task) {
387 387
                 return null;
388 388
             }
389 389
 
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
             return $this->saveOrFail($task);
397 397
         });
398 398
 
399
-        if (! $task) {
399
+        if (!$task) {
400 400
             return null;
401 401
         }
402 402
 
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
         ];
418 418
         $task = $this->patchEntity($task, $fields);
419 419
 
420
-        return (bool) $this->save($task);
420
+        return (bool)$this->save($task);
421 421
     }
422 422
 
423 423
     /**
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
         ];
438 438
         $task = $this->patchEntity($task, $fields);
439 439
 
440
-        return (bool) $this->save($task);
440
+        return (bool)$this->save($task);
441 441
     }
442 442
 
443 443
     /**
@@ -496,12 +496,12 @@  discard block
 block discarded – undo
496 496
      */
497 497
     public function cleanOldJobs()
498 498
     {
499
-        if (! Configure::read('Queue.cleanuptimeout')) {
499
+        if (!Configure::read('Queue.cleanuptimeout')) {
500 500
             return;
501 501
         }
502 502
 
503 503
         $this->deleteAll([
504
-            'completed <' => time() - (int) Configure::read('Queue.cleanuptimeout')
504
+            'completed <' => time() - (int)Configure::read('Queue.cleanuptimeout')
505 505
         ]);
506 506
     }
507 507
 
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
             return $this->_key;
541 541
         }
542 542
         $this->_key = sha1(microtime());
543
-        if (! $this->_key) {
543
+        if (!$this->_key) {
544 544
             throw new RuntimeException('Invalid key generated');
545 545
         }
546 546
 
Please login to merge, or discard this patch.