QueueListener::handleMessage()   A
last analyzed

Complexity

Conditions 4
Paths 7

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 7
nop 2
dl 0
loc 16
ccs 0
cts 13
cp 0
crap 20
rs 10
1
<?php
2
3
4
namespace Xervice\EventRabbitMq\Business\Plugin\Listener;
5
6
7
use DataProvider\RabbitMqMessageCollectionDataProvider;
0 ignored issues
show
Bug introduced by
The type DataProvider\RabbitMqMessageCollectionDataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use PhpAmqpLib\Channel\AMQPChannel;
9
use Xervice\EventRabbitMq\Business\Exception\EventFailException;
10
use Xervice\RabbitMQ\Business\Model\Worker\Listener\AbstractListener;
11
12
/**
13
 * @method \Xervice\EventRabbitMq\Business\EventRabbitMqBusinessFactory getFactory()
14
 */
15
class QueueListener extends AbstractListener
16
{
17
    public function handleMessage(
18
        RabbitMqMessageCollectionDataProvider $collectionDataProvider,
19
        AMQPChannel $channel
20
    ): void {
21
22
        foreach ($collectionDataProvider->getMessages() as $message) {
23
            $event = $message->getMessage();
24
25
            try {
26
                if ($event->hasName()) {
27
                    $this->getFactory()->getEventFacade()->eventToListener($event);
28
                }
29
30
                $this->sendAck($channel, $message);
31
            } catch (EventFailException $exception) {
32
                $this->sendNack($channel, $message);
33
            }
34
        }
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getQueueName(): string
41
    {
42
        return $this->getFactory()->createEventQueue()->getName();
43
    }
44
45
    /**
46
     * @return int
47
     */
48
    public function getChunkSize(): int
49
    {
50
        return 1000;
51
    }
52
}