RpcQueueCallback   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getQueueService() 0 4 1
A toClosure() 0 20 1
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Transport\Rpc;
4
5
use Cmobi\RabbitmqBundle\Queue\CmobiAMQPMessage;
6
use Cmobi\RabbitmqBundle\Queue\QueueCallbackInterface;
7
use Cmobi\RabbitmqBundle\Queue\QueueServiceInterface;
8
use PhpAmqpLib\Message\AMQPMessage;
9
10
class RpcQueueCallback implements QueueCallbackInterface
11
{
12
    private $queueService;
13
14
    public function __construct(QueueServiceInterface $queueService)
15
    {
16
        $this->queueService = $queueService;
17
    }
18
19
    /**
20
     * @return QueueServiceInterface
21
     */
22
    public function getQueueService()
23
    {
24
        return $this->queueService;
25
    }
26
27
    /**
28
     * @return \Closure
29
     */
30
    public function toClosure()
31
    {
32
        return function (AMQPMessage $message) {
33
            $response = $this->getQueueService()->handle($message);
34
35
            $amqpResponse = new CmobiAMQPMessage(
36
                (string) $response,
37
                ['correlation_id' => $message->get('correlation_id')]
38
            );
39
40
            $message->delivery_info['channel']->basic_publish(
41
                $amqpResponse,
42
                '',
43
                $message->get('reply_to')
44
            );
45
            $message->delivery_info['channel']->basic_ack(
46
                $message->delivery_info['delivery_tag']
0 ignored issues
show
Documentation introduced by
$message->delivery_info['delivery_tag'] is of type object<PhpAmqpLib\Channel\AMQPChannel>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
            );
48
        };
49
    }
50
}
51