Passed
Pull Request — master (#140)
by Alexander
05:08 queued 02:34
created

QueueCollector::collectWorkerProcessing()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 2
crap 2.0625
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Yiisoft\Yii\Queue\Message\MessageInterface;
8
use Yiisoft\Yii\Queue\QueueInterface;
9
10
final class QueueCollector implements CollectorInterface, IndexCollectorInterface
11
{
12
    use CollectorTrait;
13
14
    private array $pushes = [];
15
    private array $statuses = [];
16
    private array $processingMessages = [];
17
18 1
    public function getCollected(): array
19
    {
20
        return [
21 1
            'pushes' => $this->pushes,
22 1
            'statuses' => $this->statuses,
23 1
            'processingMessages' => $this->processingMessages,
24
        ];
25
    }
26
27 1
    public function collectStatus(string $id): void
28
    {
29 1
        if (!$this->isActive()) {
30
            return;
31
        }
32
33 1
        $this->statuses[] = $id;
34
    }
35
36 1
    public function collectPush(string $channel, MessageInterface $message): void
37
    {
38 1
        if (!$this->isActive()) {
39
            return;
40
        }
41 1
        $this->pushes[$channel][] = $message;
42
    }
43
44 1
    public function collectWorkerProcessing(MessageInterface $message, QueueInterface $queue)
45
    {
46 1
        if (!$this->isActive()) {
47
            return;
48
        }
49 1
        $this->processingMessages[$queue->getChannelName()][] = $message;
50
    }
51
52 1
    private function reset(): void
0 ignored issues
show
Unused Code introduced by
The method reset() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
53
    {
54 1
        $this->pushes = [];
55 1
        $this->statuses = [];
56 1
        $this->processingMessages = [];
57
    }
58
59 1
    public function getIndexData(): array
60
    {
61 1
        $countPushes = array_sum(array_map(fn ($messages) => count($messages), $this->pushes));
62 1
        $countStatuses = count($this->statuses);
63 1
        $countProcessingMessages = array_sum(array_map(fn ($messages) => count($messages), $this->processingMessages));
64
65
        return [
66
            'queue' => [
67
                'countPushes' => $countPushes,
68
                'countStatuses' => $countStatuses,
69
                'countProcessingMessages' => $countProcessingMessages,
70
            ],
71
        ];
72
    }
73
}
74