Completed
Push — master ( 613d98...fa04c9 )
by Rémi
20:40
created

SyncPublisher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B publish() 0 25 2
1
<?php
2
3
namespace Burrow\Publisher;
4
5
use Burrow\Driver;
6
use Burrow\Message;
7
use Burrow\QueueHandler;
8
use Burrow\QueuePublisher;
9
10
class SyncPublisher implements QueuePublisher
11
{
12
    /** @var Driver */
13
    private $driver;
14
15
    /** @var string */
16
    private $exchangeName;
17
18
    /** @var int */
19
    private $timeout;
20
21
    /**
22
     * Constructor
23
     *
24
     * @param Driver $driver
25
     * @param string $exchangeName
26
     * @param int    $timeout
27
     */
28
    public function __construct(Driver $driver, $exchangeName, $timeout = 10)
29
    {
30
        $this->driver = $driver;
31
        $this->exchangeName = $exchangeName;
32
        $this->timeout = $timeout;
33
    }
34
35
    /**
36
     * Publish a message on the queue
37
     *
38
     * @param mixed    $data
39
     * @param string   $routingKey
40
     * @param string[] $headers
41
     *
42
     * @return mixed
43
     */
44
    public function publish($data, $routingKey = '', array $headers = [])
45
    {
46
        $response = null;
47
        $correlationId = uniqid();
48
        $replyTo = $this->driver->declareSimpleQueue('', Driver::QUEUE_EXCLUSIVE);
49
50
        $this->driver->publish(
51
            $this->exchangeName,
52
            new Message($data, $routingKey, $headers, $correlationId, $replyTo)
0 ignored issues
show
Documentation introduced by
$headers is of type array<integer,string>, but the function expects a array<integer,object<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...
53
        );
54
55
        $this->driver->consume(
56
            $replyTo,
57
            function (Message $message) use ($replyTo, $correlationId, &$response) {
58
                if ($message->getCorrelationId() == $correlationId) {
59
                    $response = $message->getBody();
60
                    return QueueHandler::STOP_CONSUMING;
61
                }
62
                return QueueHandler::CONTINUE_CONSUMING;
63
            },
64
            $this->timeout
65
        );
66
67
        return $response;
68
    }
69
}
70