From de8a2c223d11053986a0b8e81fec673fe5f1a9fe Mon Sep 17 00:00:00 2001 From: Georg Ringer Date: Sun, 3 Apr 2022 11:41:35 +0200 Subject: [PATCH] [RateLimiter] Add typecase to SlidingWindow::getExpirationTime --- src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php | 2 +- .../Component/RateLimiter/Tests/Policy/SlidingWindowTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php b/src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php index 1eed0cbc6ec42..e79822801e6bf 100644 --- a/src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php +++ b/src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php @@ -76,7 +76,7 @@ public function getId(): string */ public function getExpirationTime(): int { - return $this->windowEndAt + $this->intervalInSeconds - microtime(true); + return (int) ($this->windowEndAt + $this->intervalInSeconds - microtime(true)); } public function isExpired(): bool diff --git a/src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowTest.php b/src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowTest.php index f63ec433e6344..ea4109a7c57e2 100644 --- a/src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowTest.php +++ b/src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowTest.php @@ -34,6 +34,9 @@ public function testGetExpirationTime() $new = SlidingWindow::createFromPreviousWindow($cachedWindow, 15); $this->assertSame(2 * 15, $new->getExpirationTime()); + + usleep(10.1); + $this->assertIsInt($new->getExpirationTime()); } public function testInvalidInterval()