| Total Complexity | 8 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class Sequence |
||
| 17 | { |
||
| 18 | use TLang; |
||
| 19 | |||
| 20 | protected int $key = 0; |
||
| 21 | protected float $created = 0.0; |
||
| 22 | protected float $done = 0.0; |
||
| 23 | protected float $length = 0.0; |
||
| 24 | |||
| 25 | 1 | public static function newSequence(?IRRTranslations $lang = null): self |
|
| 26 | { |
||
| 27 | 1 | $lib = new static($lang); |
|
| 28 | 1 | return $lib->generateSequence(); |
|
| 29 | } |
||
| 30 | |||
| 31 | 4 | final public function __construct(?IRRTranslations $lang = null) |
|
| 32 | { |
||
| 33 | 4 | $this->setRRLang($lang); |
|
| 34 | } |
||
| 35 | |||
| 36 | 3 | public function generateSequence(): self |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @return int |
||
| 45 | * @codeCoverageIgnore because how to process random number? |
||
| 46 | */ |
||
| 47 | protected function getRandInitial(): int |
||
| 48 | { |
||
| 49 | return rand(0, 65535); |
||
| 50 | } |
||
| 51 | |||
| 52 | 3 | public function getKey(): int |
|
| 53 | { |
||
| 54 | 3 | return $this->key; |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param int $sequence |
||
| 59 | * @throws RequestException |
||
| 60 | * @return $this |
||
| 61 | */ |
||
| 62 | 3 | public function checkSequence(int $sequence): self |
|
| 63 | { |
||
| 64 | 3 | if ($this->key != $sequence) { |
|
| 65 | 1 | throw new RequestException($this->getRRLang()->rrFspWrongSequence($sequence, $this->key)); |
|
| 66 | } |
||
| 67 | 2 | return $this; |
|
| 68 | } |
||
| 69 | |||
| 70 | 2 | public function updateSequence(): self |
|
| 75 | } |
||
| 76 | } |
||
| 77 |