Completed
Push — master ( d28680...48d96a )
by Olivier
01:31
created

StatefulStompMessageProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 5
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 Client $client
29
     * @param string $destination
30
     * @param null   $selector
31
     * @param string $ack
32
     * @param array  $header
33
     */
34 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
        Client $client,
36
        $destination,
37
        $selector = null,
38
        $ack = 'client',
39
        array $header = []
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        if ($frame = $this->stomp->read()) {
51
            return new Message($frame->getBody(), $frame->getHeaders());
52
        }
53
54
        return null;
55
    }
56
57
    /**
58
     * @param Message $message
59
     */
60
    public function ack(Message $message)
61
    {
62
        $this->stomp->ack(new StompMessage($message->getBody(), $message->getProperties()));
63
    }
64
65
    /**
66
     * @param Message $message
67
     * @param bool    $requeue
68
     */
69
    public function nack(Message $message, $requeue = false)
70
    {
71
        $this->stomp->nack(new StompMessage($message->getBody(), $message->getProperties()), $requeue);
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getQueueName()
78
    {
79
        return $this->destination;
80
    }
81
}
82