Closed
Description
Symfony version(s) affected
6.0.7
Description
After updating RateLimiter component to 6.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.yaml
framework:
rate_limiter:
foo_action:
policy: sliding_window
limit: 15
interval: '60 minutes'
lock_factory: null
then try to use RateLimiter:
final class FooAction
{
public function __construct(
private readonly RateLimiterFactory $fooActionLimiter,
) {
}
public function __invoke()
{
$limiter = $this->fooActionLimiter
->create('test')
;
$limit = $limiter->consume();
if (false === $limit->isAccepted()) {
throw new \RuntimeException('Too many actions.');
}
}
Possible Solution
In \Symfony\Component\RateLimiter\Policy\SlidingWindow::getExpirationTime
method, $this->windowEndAt
and microtime
return value are float
s, converting type should help: return (int) $this->windowEndAt + $this->intervalInSeconds - (int) microtime(true);
or change return type to float
: public function getExpirationTime(): float
.
Additional Context
Earlier patch version (6.0.x) works without deprecation.