| Total Complexity | 9 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 |
|
| 69 | 6 | } |
|
| 70 | } |
||
| 71 |