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

ReceiverExecutorDecorator::execute()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 34
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 21
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 34
rs 9.2728
1
<?php
2
3
namespace OldSound\RabbitMqBundle\ReceiverExecutor;
4
5
use OldSound\RabbitMqBundle\Event\AfterProcessingMessagesEvent;
6
use OldSound\RabbitMqBundle\Event\BeforeProcessingMessagesEvent;
7
use OldSound\RabbitMqBundle\Logger\ExtraContextLogger;
8
use OldSound\RabbitMqBundle\RabbitMq\Consuming;
9
10
class ReceiverExecutorDecorator implements ReceiverExecutorInterface
11
{
12
    /** @var Consuming */
13
    private $consuming;
14
15
    /** @var LoggerInterface */
0 ignored issues
show
Bug introduced by
The type OldSound\RabbitMqBundle\...xecutor\LoggerInterface 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...
16
    private $logger;
17
18
    public function __construct(Consuming $consuming, LoggerInterface $logger)
19
    {
20
        $this->consuming = $consuming;
21
        $this->logger = $logger;
22
    }
23
24
    private function createLoggerExtraContext(array $messages)
25
    {
26
        $amqpContext = ['queue' => $this->consuming->options->queue];
27
        if ($this->consuming->executeReceiverStrategy->canPrecessMultiMessages()) {
28
            $amqpContext['messages'] = $messages;
29
        } else {
30
            if (count($messages) > 1) {
31
                // TODO
32
            }
33
            $amqpContext['message'] = $messages[0];
34
        }
35
        return $amqpContext;
36
    }
37
38
    public function execute(array $messages, $receiver): array
39
    {
40
        $logger = new ExtraContextLogger($this->logger, ['amqp' => $this->createLoggerExtraContext($messages)]);
41
42
        $event = new BeforeProcessingMessagesEvent($messages, $this->consuming->options);
43
        $this->dispatchEvent(BeforeProcessingMessagesEvent::NAME, $event);
0 ignored issues
show
Bug introduced by
The method dispatchEvent() does not exist on OldSound\RabbitMqBundle\...ceiverExecutorDecorator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        $this->/** @scrutinizer ignore-call */ 
44
               dispatchEvent(BeforeProcessingMessagesEvent::NAME, $event);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
        if ($event->isStoppingConsumer()) {
45
            throw new StopConsumerException();
0 ignored issues
show
Bug introduced by
The type OldSound\RabbitMqBundle\...r\StopConsumerException 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...
46
        }
47
48
        try {
49
            $flags = $this->consuming->receiverExecutor->execute($messages, $receiver);
50
        } catch (Exception\StopConsumerException $e) {
0 ignored issues
show
Bug introduced by
The type OldSound\RabbitMqBundle\...n\StopConsumerException 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...
51
            $logger->info('Consumer requested stop', [
52
                'exception' => $e
53
            ]);
54
55
            throw $e;
56
        } catch (\Throwable $e) {
57
            $logger->error('Throw exception while process messages', [
58
                'exception' => $e
59
            ]);
60
            throw $e;
61
        }
62
63
64
        $logger->info('Queue messages processed'); // TODO add flag code
65
        $event = new AfterProcessingMessagesEvent($this, $messages); // TODO add flag code
0 ignored issues
show
Bug introduced by
$this of type OldSound\RabbitMqBundle\...ceiverExecutorDecorator is incompatible with the type OldSound\RabbitMqBundle\RabbitMq\Consumer expected by parameter $consumer of OldSound\RabbitMqBundle\...gesEvent::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        $event = new AfterProcessingMessagesEvent(/** @scrutinizer ignore-type */ $this, $messages); // TODO add flag code
Loading history...
66
        $this->dispatchEvent(AfterProcessingMessagesEvent::NAME, $event);
67
        if ($event->isStoppingConsumer()) {
68
            throw new StopConsumerException();
69
        }
70
71
        return $flags;
72
    }
73
74
    public function support($receiver): bool
75
    {
76
        return $this->consuming->receiverExecutor->support($receiver);
77
    }
78
}