Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[RateLimiter] Deprecation "Implicit conversion from float x.xxx to int loses precision" #45949

Copy link
Copy link
Closed
@PabloKowalczyk

Description

@PabloKowalczyk
Issue body actions

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 floats, 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.