RetryHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Webhook\Bundle\Service;
6
7
8
use Enqueue\Client\Message;
9
use Enqueue\Client\ProducerInterface;
10
use Webhook\Domain\Infrastructure\HandlerInterface;
11
use Webhook\Domain\Model\Webhook;
12
13
/**
14
 * Class RetryHandler
15
 *
16
 * @package Webhook\Bundle\Service
17
 */
18
final class RetryHandler implements HandlerInterface
19
{
20
    /** @var ProducerInterface */
21
    private $producer;
22
23
    /**
24
     * RatesCollector constructor.
25
     *
26
     * @param ProducerInterface $producer
27
     */
28
    public function __construct(ProducerInterface $producer)
29
    {
30
        $this->producer = $producer;
31
    }
32
33
    /**
34
     * @param Webhook $webhook
35
     *
36
     * @return void
37
     */
38
    public function handle(Webhook $webhook)
39
    {
40
        $id = $webhook->getId();
41
42
        $delay = $webhook->getNextAttempt()->getTimestamp() - time();
43
44
        $message = new Message($id);
45
        $message->setDelay($delay);
46
47
        $this->producer->sendCommand(WebhookProcessor::NAME, $message);
48
    }
49
}