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