| Total Complexity | 8 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Coverage | 90.91% |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class Sequence |
||
| 16 | { |
||
| 17 | /** @var IRRTranslations */ |
||
| 18 | protected $lang = null; |
||
| 19 | /** @var int */ |
||
| 20 | protected $key = 0; |
||
| 21 | /** @var float */ |
||
| 22 | protected $created = 0.0; |
||
| 23 | /** @var float */ |
||
| 24 | protected $done = 0.0; |
||
| 25 | /** @var float */ |
||
| 26 | protected $length = 0.0; |
||
| 27 | |||
| 28 | 1 | public static function newSequence(IRRTranslations $lang): self |
|
| 29 | { |
||
| 30 | 1 | $lib = new static($lang); |
|
| 31 | 1 | return $lib->generateSequence(); |
|
| 32 | } |
||
| 33 | |||
| 34 | 4 | final public function __construct(IRRTranslations $lang) |
|
| 35 | { |
||
| 36 | 4 | $this->lang = $lang; |
|
| 37 | 4 | } |
|
| 38 | |||
| 39 | 3 | public function generateSequence(): self |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return int |
||
| 48 | * @codeCoverageIgnore because how to process random number? |
||
| 49 | */ |
||
| 50 | protected function getRandInitial(): int |
||
| 51 | { |
||
| 52 | return rand(0, 65535); |
||
| 53 | } |
||
| 54 | |||
| 55 | 3 | public function getKey(): int |
|
| 56 | { |
||
| 57 | 3 | return $this->key; |
|
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param int $sequence |
||
| 62 | * @throws RequestException |
||
| 63 | * @return $this |
||
| 64 | */ |
||
| 65 | 3 | public function checkSequence(int $sequence): self |
|
| 66 | { |
||
| 67 | 3 | if ($this->key != $sequence) { |
|
| 68 | 1 | throw new RequestException($this->lang->rrFspWrongSequence($sequence, $this->key)); |
|
| 69 | } |
||
| 70 | 2 | return $this; |
|
| 71 | } |
||
| 72 | |||
| 73 | 2 | public function updateSequence(): self |
|
| 78 | } |
||
| 79 | } |
||
| 80 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.