Completed
Pull Request — master (#5)
by Quim
04:42 queued 02:24
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 Infrastructure\AmqpLib\v26\RabbitMQ\Queue;
10
11
use Domain\Queue\JSONMessageFactory;
12
use PhpAmqpLib\Message\AMQPMessage;
13
14
class MessageHandler
15
{
16
    /**
17
     * @var JSONMessageFactory
18
     */
19
    private $jsonMessageFactory;
20
21
    /**
22
     * @var callable
23
     */
24
    private $callback;
25
26
    /**
27
     * MessageHandler constructor.
28
     * @param JSONMessageFactory $jsonMessageFactory
29
     */
30
    public function __construct(JSONMessageFactory $jsonMessageFactory)
31
    {
32
        $this->jsonMessageFactory = $jsonMessageFactory;
33
    }
34
35
    /**
36
     * @param AMQPMessage $message
37
     * @throws \Exception
38
     */
39
    public function handleMessage(AMQPMessage $message)
40
    {
41
        try {
42
            $task = $this->jsonMessageFactory->create($message->body);
43
            call_user_func_array($this->callback, [$task]);
44
            $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...
45
        } catch (\Exception $e) {
46
            throw $e;
47
        }
48
    }
49
50
    public function setCallback(callable $callback)
51
    {
52
        $this->callback = $callback;
53
    }
54
}