Completed
Pull Request — master (#10)
by
unknown
11:04
created

DelayService::delayQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\QueueBundle\Service;
6
7
use DateTime;
8
use Lamoda\QueueBundle\Entity\QueueEntityInterface;
9
10
class DelayService
11
{
12
    /**
13
     * @var ResolverStrategyService
14
     */
15
    protected $strategyService;
16
17
18 1
    public function __construct(ResolverStrategyService $strategyService)
19
    {
20 1
        $this->strategyService = $strategyService;
21 1
    }
22
23 1
    public function delayQueue(QueueEntityInterface $queue): QueueEntityInterface
24
    {
25 1
        $strategy         = $this->strategyService->getStrategy($queue->getName());
26 1
        $iteration        = $queue->getAttempts() ?? 1;
27 1
        $newDelayInterval = $strategy->generateInterval($iteration);
28 1
        $delayUntil       = $this->getStartDateTime()->add($newDelayInterval);
29
30 1
        $queue->setWaiting($delayUntil);
31
32 1
        return $queue;
33
    }
34
35
    protected function getStartDateTime(): DateTime
36
    {
37
        return new DateTime();
38
    }
39
}
40