Step::getStepCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PanicLabCore\Structs;
6
7
use PanicLabCore\Services\Exceptions\TooManyStepsException;
8
use function sprintf;
9
10
class Step
11
{
12
    /** @var int */
13
    private $currentIndex;
14
15
    /** @var int */
16
    private $stepCount;
17
18
    /** @var int */
19
    private $maxStep;
20
21 24
    public function __construct(int $currentIndex, int $stepCount, int $maxStep)
22
    {
23 24
        $this->currentIndex = $currentIndex;
24 24
        $this->stepCount = $stepCount;
25 24
        $this->maxStep = $maxStep;
26 24
    }
27
28 16
    public function getCurrentIndex(): int
29
    {
30 16
        return $this->currentIndex;
31
    }
32
33 5
    public function getStepCount(): int
34
    {
35 5
        return $this->stepCount;
36
    }
37
38 3
    public function getMaxStep(): int
39
    {
40 3
        return $this->maxStep;
41
    }
42
43
    /**
44
     * @throws TooManyStepsException
45
     */
46 10
    public function increase(): void
47
    {
48 10
        ++$this->stepCount;
49
50 10
        if ($this->stepCount === $this->maxStep) {
51 2
            throw new TooManyStepsException(sprintf('Step limit of %d reached', $this->maxStep));
52
        }
53
54 10
        ++$this->currentIndex;
55 10
    }
56
57 7
    public function checkForOverstep(int $totalCount): void
58
    {
59 7
        if ($this->currentIndex <= $totalCount - 1) {
60 6
            return;
61
        }
62
63 3
        $this->currentIndex = 0;
64 3
    }
65
66 6
    public function setCurrentIndex(int $currentIndex): void
67
    {
68 6
        $this->currentIndex = $currentIndex;
69 6
    }
70
}
71