Lines
100.00%
8 / 8
Methods
100.00%
6 / 6
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| beginReload | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| abandonReload | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| recordResult | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| isUnderway | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| findLastResult | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| countResults | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 9 | final class ReloadState | |
| 10 | { | |
| 11 | private bool $underway = false; | |
| 12 | ||
| 13 | private ?ReloadResult $lastResult = null; | |
| 14 | ||
| 15 | /** @var array<string, int> */ | |
| 16 | private array $resultCounts = []; | |
| 17 | ||
| 18 | public function beginReload(): void | |
| 19 | { | |
| 20 | $this->underway = true; | |
| 21 | } | |
| 22 | ||
| 23 | public function abandonReload(): void | |
| 24 | { | |
| 25 | $this->underway = false; | |
| 26 | } | |
| 27 | ||
| 28 | public function recordResult(ReloadResult $result): void | |
| 29 | { | |
| 30 | $this->underway = false; | |
| 31 | $this->lastResult = $result; | |
| 32 | $this->resultCounts[$result->outcome->value] = $this->countResults($result->outcome) + 1; | |
| 33 | } | |
| 34 | ||
| 35 | public function isUnderway(): bool | |
| 36 | { | |
| 37 | return $this->underway; | |
| 38 | } | |
| 39 | ||
| 40 | public function findLastResult(): ?ReloadResult | |
| 41 | { | |
| 42 | return $this->lastResult; | |
| 43 | } | |
| 44 | ||
| 45 | public function countResults(ReloadOutcome $outcome): int | |
| 46 | { | |
| 47 | return $this->resultCounts[$outcome->value] ?? 0; | |
| 48 | } | |
| 49 | } |