Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Closed
Description
Symfony version(s) affected
6.0.7
Description
After updating RateLimiter component to6.0.7
tests starts to showing "Implicit conversion from float x.xxx to int loses precision" deprecation message. I'm using sliding window policy.
How to reproduce
Example Symfony config
# config/packages/framework.yamlframework:rate_limiter:foo_action:policy:sliding_windowlimit:15interval:'60 minutes'lock_factory:null
then try to use RateLimiter:
finalclass FooAction{publicfunction__construct(privatereadonlyRateLimiterFactory$fooActionLimiter, ) { }publicfunction__invoke() {$limiter =$this->fooActionLimiter ->create('test') ;$limit =$limiter->consume();if (false ===$limit->isAccepted()) {thrownew \RuntimeException('Too many actions.'); } }
Possible Solution
In\Symfony\Component\RateLimiter\Policy\SlidingWindow::getExpirationTime
method,$this->windowEndAt
andmicrotime
return value arefloat
s, converting type should help:return (int) $this->windowEndAt + $this->intervalInSeconds - (int) microtime(true);
or change return type tofloat
:public function getExpirationTime(): float
.
Additional Context
Earlier patch version (6.0.x) works without deprecation.