Issues (219)

Redis/StatusTrait.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Dtc\QueueBundle\Redis;
4
5
use Dtc\QueueBundle\Model\BaseJob;
6
7
trait StatusTrait
8
{
9 3
    protected function collateStatusResults(array &$results, $cacheKey)
10
    {
11 3
        $cursor = null;
12 3
        while ($jobs = $this->redis->zScan($cacheKey, $cursor, '', 100)) {
13 3
            $jobs = $this->redis->mget(array_map(function ($item) {
14 3
                return $this->getJobCacheKey($item);
0 ignored issues
show
It seems like getJobCacheKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
                return $this->/** @scrutinizer ignore-call */ getJobCacheKey($item);
Loading history...
15 3
            }, array_keys($jobs)));
16 3
            $this->extractStatusResults($jobs, $results);
17 3
            if (0 === $cursor) {
18 3
                break;
19
            }
20
        }
21
22 3
        return $results;
23
    }
24
25 3
    protected function extractStatusResults(array $jobs, array &$results)
26
    {
27 3
        foreach ($jobs as $jobMessage) {
28 3
            if (is_string($jobMessage)) {
29 3
                $job = new Job();
30 3
                $job->fromMessage($jobMessage);
31 3
                $resultHashKey = $job->getWorkerName().'->'.$job->getMethod().'()';
32 3
                if (!isset($results[$resultHashKey][BaseJob::STATUS_NEW])) {
33 3
                    $results[$resultHashKey] = static::getAllStatuses();
34
                }
35 3
                if (!isset($results[$resultHashKey][BaseJob::STATUS_NEW])) {
36
                    $results[$resultHashKey][BaseJob::STATUS_NEW] = 0;
37
                }
38 3
                ++$results[$resultHashKey][BaseJob::STATUS_NEW];
39
            }
40
        }
41 3
    }
42
43 2
    protected function extractStatusHashResults(array $hResults, array &$results)
44
    {
45 2
        foreach ($hResults as $key => $value) {
46 2
            list($workerName, $method, $status) = explode(',', $key);
47 2
            $resultHashKey = $workerName.'->'.$method.'()';
48 2
            if (!isset($results[$resultHashKey])) {
49
                $results[$resultHashKey] = static::getAllStatuses();
50
            }
51 2
            if (!isset($results[$resultHashKey][$status])) {
52
                $results[$resultHashKey][$status] = 0;
53
            }
54 2
            $results[$resultHashKey][$status] += $value;
55
        }
56 2
    }
57
}
58