Completed
Push — master ( 4cd93a...e8f4ec )
by Thomas Mauro
10:51
created

ConsumerCallback::getMessageMapper()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 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 5
    public function __construct(callable $callback, Queue $queue)
29
    {
30 5
        $this->callback = $callback;
31 5
        $this->queue = $queue;
32 5
    }
33
34
    /**
35
     * @param AMQPMessage $message
36
     * @return mixed
37
     * @throws \OutOfBoundsException
38
     */
39 1
    public function __invoke(AMQPMessage $message)
40
    {
41 1
        $convertedMessage = $this->getMessageMapper()->toMessage($message);
42 1
        $ret = call_user_func($this->callback, $convertedMessage, $this->queue);
43 1
        if (false === $ret) {
44
            $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 1
        return $ret;
47
    }
48
49
    /**
50
     * @return MessageMapper
51
     */
52 2
    public function getMessageMapper()
53
    {
54 2
        if (!$this->messageMapper) {
55 1
            $this->messageMapper = new MessageMapper();
56
        }
57 2
        return $this->messageMapper;
58
    }
59
60
    /**
61
     * @param MessageMapper $messageMapper
62
     * @return $this
63
     */
64 5
    public function setMessageMapper($messageMapper)
65
    {
66 5
        $this->messageMapper = $messageMapper;
67 5
        return $this;
68
    }
69
}
70