Completed
Push — master ( 30a20d...fc5180 )
by Dmytro
05:18
created

WebhookProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Webhook\Bundle\Service;
5
6
7
use Enqueue\Client\CommandSubscriberInterface;
8
use Interop\Queue\PsrContext;
9
use Interop\Queue\PsrMessage;
10
use Interop\Queue\PsrProcessor;
11
12
/**
13
 * Class WebhookProcessor
14
 *
15
 * @package Webhook\Bundle\Service
16
 */
17
final class WebhookProcessor implements PsrProcessor, CommandSubscriberInterface
18
{
19
    public const NAME = 'webhook-processor';
20
21
    /** @var WebhookConsumer */
22
    private $consumer;
23
24
    /**
25
     * RatesProcessor constructor.
26
     *
27
     * @param WebhookConsumer $consumer
28
     */
29
    public function __construct(WebhookConsumer $consumer)
30
    {
31
        $this->consumer = $consumer;
32
    }
33
34
    /**
35
     * @param PsrMessage $message
36
     * @param PsrContext $context
37
     *
38
     * @return string
39
     */
40
    public function process(PsrMessage $message, PsrContext $context): string
41
    {
42
        $id = $message->getBody();
43
44
        $this->consumer->consume($id);
45
46
        return self::ACK;
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    public static function getSubscribedCommand(): array
53
    {
54
        return [
55
            'processorName' => self::NAME,
56
57
            // these are optional, setting these option we make the migration smooth and backward compatible.
58
            'queueName' => 'webhooks',
59
            'queueNameHardcoded' => true,
60
            'exclusive' => true,
61
        ];
62
    }
63
}
64