MessageDataCollector::getPublishedMessagesLog()   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
ccs 0
cts 2
cp 0
crap 2
rs 10
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
    public function __construct($channels)
19
    {
20
        $this->channels = $channels;
21
        $this->data = [];
22
    }
23
24
    public function collect(Request $request, Response $response, ?\Throwable $exception = null)
25
    {
26
        foreach ($this->channels as $channel) {
27
            foreach ($channel->getBasicPublishLog() as $log) {
28
                $this->data[] = $log;
29
            }
30
        }
31
    }
32
33
    public function getName()
34
    {
35
        return 'rabbit_mq';
36
    }
37
38
    public function getPublishedMessagesCount()
39
    {
40
        return count($this->data);
41
    }
42
43
    public function getPublishedMessagesLog()
44
    {
45
        return $this->data;
46
    }
47
48
    public function reset()
49
    {
50
        $this->data = [];
51
    }
52
}
53