Completed
Push — master ( d972fa...aafada )
by Dmytro
13:29
created

LinearStrategy::setMultiplier()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 1
crap 3.072
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Webhook\Domain\Infrastructure\Strategy;
6
7
/**
8
 * Class LinearStrategy.
9
 */
10
final class LinearStrategy extends AbstractStrategy implements SetOptionsInterface
11
{
12
    /** @var int */
13
    protected $interval;
14
15
    /** @var int */
16
    protected $multiplier;
17
18
    /**
19
     * @param int $interval
20
     * @param int $multiplier
21
     */
22 12
    public function __construct(int $interval = 5, int $multiplier = 1)
23
    {
24 12
        $this->setInterval($interval);
25 11
        $this->setMultiplier($multiplier);
26 11
    }
27
28
    /**
29
     * @param int $interval
30
     */
31 12 View Code Duplication
    public function setInterval($interval)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33 12
        if (!is_int($interval) || (int) $interval < 0) {
34 1
            throw new \InvalidArgumentException('Interval should be positive integer');
35
        }
36
37 11
        $this->interval = (int) $interval;
38 11
    }
39
40
    /**
41
     * @param int $multiplier
42
     */
43 11
    public function setMultiplier($multiplier)
44
    {
45 11
        if (!is_int($multiplier) || $multiplier < 1) {
46
            throw new \InvalidArgumentException('Multiplier should be positive integer');
47
        }
48
49 11
        $this->multiplier = $multiplier;
50 11
    }
51
52
    /**
53
     *
54
     * @param int $attempt
55
     *
56
     * @return int
57
     */
58 11
    public function process(int $attempt): int
59
    {
60 11
        return $this->interval * $this->multiplier * $attempt;
61
    }
62
}