ConsumerCallback   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
c 2
b 1
f 0
lcom 1
cbo 3
dl 0
loc 63
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMessageMapper() 0 7 2
A setMessageMapper() 0 5 1
A __invoke() 0 9 2
1
<?php
2
3
namespace AMQPAL\Adapter\PhpAmqpLib;
4
5
use PhpAmqpLib\Message\AMQPMessage;
6
7
class ConsumerCallback
8
{
9
    /**
10
     * @var callable
11
     */
12
    protected $callback;
13
    /**
14
     * @var Queue
15
     */
16
    protected $queue;
17
    /**
18
     * @var MessageMapper
19
     */
20
    protected $messageMapper;
21
22
    /**
23
     * ConsumerCallback constructor.
24
     *
25
     * @param callable $callback
26
     * @param Queue    $queue
27
     */
28 9
    public function __construct(callable $callback, Queue $queue)
29
    {
30 9
        $this->callback = $callback;
31 9
        $this->queue = $queue;
32 9
    }
33
34
    /**
35
     * @param AMQPMessage $message
36
     * @return mixed
37
     * @throws \OutOfBoundsException
38
     */
39 5
    public function __invoke(AMQPMessage $message)
40
    {
41 5
        $convertedMessage = $this->getMessageMapper()->toMessage($message);
42 5
        $ret = call_user_func($this->callback, $convertedMessage, $this->queue);
43 5
        if (false === $ret) {
44 4
            $this->queue->cancel($message->delivery_info['consumer_tag']);
0 ignored issues
show
Documentation introduced by
$message->delivery_info['consumer_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...
45
        }
46 5
        return $ret;
47
    }
48
49
    /**
50
     * @return MessageMapper
51
     */
52 6
    public function getMessageMapper()
53
    {
54 6
        if (!$this->messageMapper) {
55 1
            $this->messageMapper = new MessageMapper();
56
        }
57 6
        return $this->messageMapper;
58
    }
59
60
    /**
61
     * @param MessageMapper $messageMapper
62
     * @return $this
63
     */
64 9
    public function setMessageMapper($messageMapper)
65
    {
66 9
        $this->messageMapper = $messageMapper;
67 9
        return $this;
68
    }
69
}
70