MessageDataCollector::reset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
3
namespace OldSound\RabbitMqBundle\DataCollector;
4
5
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
9
/**
10
 * MessageDataCollector
11
 *
12
 * @author Marc Weistroff <[email protected]>
13
 */
14
class MessageDataCollector extends DataCollector
15
{
16
    private $channels;
17
18
    /** @var array */
19
    private $messages;
20
21
    public function __construct($channels)
22
    {
23
        $this->channels = $channels;
24
        $this->messages = [];
25
    }
26
27
    public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
28
    {
29
        foreach ($this->channels as $channel) {
30
            foreach ($channel->getBasicPublishLog() as $log) {
31
                $this->messages[] = $log;
32
            }
33
        }
34
    }
35
36
    public function getName(): string
37
    {
38
        return 'rabbit_mq';
39
    }
40
41
    public function getPublishedMessagesCount(): int
42
    {
43
        return count($this->messages);
44
    }
45
46
    public function getPublishedMessagesLog(): array
47
    {
48
        return $this->messages;
49
    }
50
51
    public function reset(): void
52
    {
53
        $this->messages = [];
54
    }
55
}
56