ExponentialRetryScheduler::scheduleNextRetry()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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