Completed
Push — master ( cc905d...92a60b )
by Olivier
22s queued 11s
created

MessageProvider/StatefulStompMessageProvider.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Swarrot\Broker\MessageProvider;
4
5
use Stomp\Client;
6
use Stomp\StatefulStomp;
7
use Stomp\Transport\Message as StompMessage;
8
use Swarrot\Broker\Message;
9
10
class StatefulStompMessageProvider implements MessageProviderInterface
11
{
12
    /**
13
     * @var Client
14
     */
15
    private $client;
16
17
    /**
18
     * @var StatefulStomp
19
     */
20
    private $stomp;
21
22
    /**
23
     * @var string
24
     */
25
    private $destination;
26
27
    /**
28
     * @param string $destination
29
     * @param null   $selector
30
     * @param string $ack
31
     */
32 View Code Duplication
    public function __construct(
33
        Client $client,
34
        $destination,
35
        $selector = null,
36
        $ack = 'client',
37
        array $header = []
38
    ) {
39
        @trigger_error(sprintf('"%s" have been deprecated since Swarrot 3.6', __CLASS__), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
40
41
        $this->client = $client;
42
        $this->destination = $destination;
43
44
        $this->stomp = new StatefulStomp($client);
45
        $this->stomp->subscribe($destination, $selector, $ack, $header);
46
    }
47
48 View Code Duplication
    public function get()
49
    {
50
        if ($frame = $this->stomp->read()) {
51
            return new Message($frame->getBody(), $frame->getHeaders());
52
        }
53
54
        return null;
55
    }
56
57
    public function ack(Message $message)
58
    {
59
        $this->stomp->ack(new StompMessage($message->getBody(), $message->getProperties()));
60
    }
61
62
    /**
63
     * @param bool $requeue
64
     */
65
    public function nack(Message $message, $requeue = false)
66
    {
67
        $this->stomp->nack(new StompMessage($message->getBody(), $message->getProperties()), $requeue);
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getQueueName()
74
    {
75
        return $this->destination;
76
    }
77
}
78