Completed
Push — master ( 5fca0d...2a987b )
by Quim
02:16
created

MessageHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
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 handleMessage() 0 10 2
A setCallback() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: quimmanrique
5
 * Date: 13/02/17
6
 * Time: 19:13
7
 */
8
9
namespace Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue;
10
11
use Cmp\Queues\Domain\Queue\JSONMessageFactory;
12
use PhpAmqpLib\Message\AMQPMessage;
13
use Psr\Log\LoggerInterface;
14
15
class MessageHandler
16
{
17
    /**
18
     * @var JSONMessageFactory
19
     */
20
    private $jsonMessageFactory;
21
22
    /**
23
     * @var callable
24
     */
25
    private $callback;
26
27
    /**
28
     * MessageHandler constructor.
29
     * @param JSONMessageFactory $jsonMessageFactory
30
     */
31
    public function __construct(JSONMessageFactory $jsonMessageFactory)
32
    {
33
        $this->jsonMessageFactory = $jsonMessageFactory;
34
    }
35
36
    /**
37
     * @param AMQPMessage $message
38
     * @throws \Exception
39
     */
40
    public function handleMessage(AMQPMessage $message)
41
    {
42
        try {
43
            $task = $this->jsonMessageFactory->create($message->body);
44
            call_user_func_array($this->callback, [$task]);
45
            $message->delivery_info['channel']->basic_ack($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...
46
        } catch (\Exception $e) {
47
            throw $e;
48
        }
49
    }
50
51
    public function setCallback(callable $callback)
52
    {
53
        $this->callback = $callback;
54
    }
55
}