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

DelayService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 30
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A delayQueue() 0 11 1
A getStartDateTime() 0 4 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