ExponentialRetryScheduler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A scheduleNextRetry() 0 5 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusSchedulerPlugin\Retry;
6
7
use Setono\SyliusSchedulerPlugin\Model\JobInterface;
8
9
class ExponentialRetryScheduler implements RetrySchedulerInterface
10
{
11
    /**
12
     * @var int
13
     */
14
    private $base;
15
16
    /**
17
     * @param int $base
18
     */
19
    public function __construct(int $base = 5)
20
    {
21
        $this->base = $base;
22
    }
23
24
    /**
25
     * @param JobInterface $originalJob
26
     *
27
     * @return \DateTime
28
     */
29
    public function scheduleNextRetry(JobInterface $originalJob): \DateTime
30
    {
31
        return new \DateTime(sprintf(
32
            '+%s seconds',
33
            $this->base ** count($originalJob->getRetryJobs())
34
        ));
35
    }
36
}
37