Test Failed
Pull Request — master (#39)
by Aleksandr
05:36
created

BatchReceiverExecutor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A support() 0 3 1
A execute() 0 20 5
1
<?php
2
3
4
namespace OldSound\RabbitMqBundle\ReceiverExecutor;
5
6
use OldSound\RabbitMqBundle\Declarations\BatchConsumeOptions;
7
use OldSound\RabbitMqBundle\Receiver\BatchReceiverInterface;
8
9
class BatchReceiverExecutor implements ReceiverExecutorInterface
10
{
11
    /**
12
     * @param BatchReceiverInterface $receiver
13
     */
14
    public function execute($messages, $receiver): array
15
    {
16
        if (!$this->support($receiver)) {
17
            throw new \InvalidArgumentException('TOOD');
18
        }
19
        $flags = $receiver->batchExecute($messages);
20
21
        if (!is_array($flags)) { // flat flag for each delivery tag
22
            $flag = $flags;
23
            $flags = [];
24
            foreach ($messages as $message) {
25
                $flags[$message->getDeliveryTag()] = $flag;
26
            }
27
        } else if (count($flags) !== count($messages)) {
28
            throw new AMQPRuntimeException(// TODO
0 ignored issues
show
Bug introduced by
The type OldSound\RabbitMqBundle\...or\AMQPRuntimeException 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...
29
                'Method batchExecute() should return an array with elements equal with the number of messages processed'
30
            );
31
        }
32
33
        return $flags;
34
    }
35
36
    public function support($receiver): bool
37
    {
38
        return $receiver instanceof BatchReceiverInterface;
39
    }
40
}