| Conditions | 4 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 34 | public function expired(float $beta): bool |
||
| 35 | { |
||
| 36 | if ($beta < 0) { |
||
| 37 | throw new InvalidArgumentException(sprintf( |
||
| 38 | 'Argument "$beta" must be a positive number, %f given.', |
||
| 39 | $beta |
||
| 40 | )); |
||
| 41 | } |
||
| 42 | |||
| 43 | if ($this->expiry === null) { |
||
| 44 | return false; |
||
| 45 | } |
||
| 46 | |||
| 47 | if ($this->expiry <= time()) { |
||
| 48 | return true; |
||
| 49 | } |
||
| 50 | |||
| 51 | $now = microtime(true); |
||
| 52 | $delta = ceil(1000 * ($now - $this->created)) / 1000; |
||
| 53 | $expired = $now - $delta * $beta * log(random_int(1, PHP_INT_MAX) / PHP_INT_MAX); |
||
| 54 | |||
| 55 | return $this->expiry <= $expired; |
||
| 56 | } |
||
| 58 |