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

ReplyReceiverExecutor   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sendReply() 0 7 1
A execute() 0 24 6
A support() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace OldSound\RabbitMqBundle\ReceiverExecutor;
4
5
use OldSound\RabbitMqBundle\Declarations\RpcConsumeOptions;
6
use OldSound\RabbitMqBundle\Receiver\ReceiverException;
7
use OldSound\RabbitMqBundle\Receiver\ReceiverInterface;
8
use OldSound\RabbitMqBundle\Receiver\ReplyReceiverInterface;
9
10
class ReplyReceiverExecutor implements ReceiverExecutorInterface
11
{
12
    /** @var RpcConsumeOptions */
13
    protected $options;
14
15
    public function __construct(RpcConsumeOptions $options)
16
    {
17
        $this->options = $options;
18
    }
19
20
    /**
21
     * @param $receiver ReplyReceiverInterface
22
     */
23
    public function execute(array $messages, $receiver): array
24
    {
25
        if (!$this->support($receiver)) {
26
            throw new \InvalidArgumentException('TOOD');
27
        }
28
29
        if (count($messages) !== 1) {
30
            throw new \InvalidArgumentException('todo');
31
        }
32
33
        $message = $messages[0];
34
35
        if (!($message->get($this->options->replayToProperty) && $message->get($this->options->correlationIdProperty))) {
36
            throw new \InvalidArgumentException('todo'); // TODO
37
        }
38
39
        try {
40
            $reply = $receiver->execute($message);
41
        } catch (ReceiverException $exception) {
42
            return [$exception->getCode()];
43
        }
44
        $this->sendReply($message->getChannel(), $reply, $message->get($this->options->replayToProperty), $message->get($this->options->correlationIdProperty));
45
46
        return [ReceiverInterface::MSG_ACK];
47
    }
48
49
    protected function sendReply(\AMQPChannel $channel, $reply, $replyTo, $correlationId)
50
    {
51
        $body = $this->serializer->serialize($reply);
0 ignored issues
show
Bug Best Practice introduced by
The property serializer does not exist on OldSound\RabbitMqBundle\...r\ReplyReceiverExecutor. Did you maybe forget to declare it?
Loading history...
52
        $message = new AMQPMessage($body, ['content_type' => 'text/plain'] + $this->options->replayMessageProperties + [
0 ignored issues
show
Bug introduced by
The type OldSound\RabbitMqBundle\...verExecutor\AMQPMessage 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...
53
            $this->options->correlationIdProperty => $correlationId,
54
        ]);
55
        $channel->basic_publish($message , '', $replyTo);
0 ignored issues
show
Bug introduced by
The method basic_publish() does not exist on AMQPChannel. ( Ignorable by Annotation )

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

55
        $channel->/** @scrutinizer ignore-call */ 
56
                  basic_publish($message , '', $replyTo);

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...
56
    }
57
58
    public function support($receiver): bool
59
    {
60
        return $receiver instanceof ReplyReceiverInterface;
61
    }
62
}