Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  Fix implicitly-required parameters
  minor #53524 [Messenger] [AmazonSqs] Allow `async-aws/sqs` version 2 (smoench)
  Fix bad merge
  List CS fix in .git-blame-ignore-revs
  Fix implicitly-required parameters
  List CS fix in .git-blame-ignore-revs
  Apply php-cs-fixer fix --rules nullable_type_declaration_for_default_null_value
  [Messenger][AmazonSqs] Allow async-aws/sqs version 2
  • Loading branch information
nicolas-grekas committed Jan 23, 2024
2 parents ece92bf + 5b8689f commit 05ac83c
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CompoundLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(array $limiters)
$this->limiters = $limiters;
}

public function reserve(int $tokens = 1, float $maxTime = null): Reservation
public function reserve(int $tokens = 1, ?float $maxTime = null): Reservation
{
throw new ReserveNotSupportedException(__CLASS__);
}
Expand Down
2 changes: 1 addition & 1 deletion Exception/MaxWaitDurationExceededException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MaxWaitDurationExceededException extends \RuntimeException
{
private RateLimit $rateLimit;

public function __construct(string $message, RateLimit $rateLimit, int $code = 0, \Throwable $previous = null)
public function __construct(string $message, RateLimit $rateLimit, int $code = 0, ?\Throwable $previous = null)
{
parent::__construct($message, $code, $previous);

Expand Down
2 changes: 1 addition & 1 deletion Exception/RateLimitExceededException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RateLimitExceededException extends \RuntimeException
{
private RateLimit $rateLimit;

public function __construct(RateLimit $rateLimit, int $code = 0, \Throwable $previous = null)
public function __construct(RateLimit $rateLimit, int $code = 0, ?\Throwable $previous = null)
{
parent::__construct('Rate Limit Exceeded', $code, $previous);

Expand Down
2 changes: 1 addition & 1 deletion Exception/ReserveNotSupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class ReserveNotSupportedException extends \BadMethodCallException
{
public function __construct(string $limiterClass, int $code = 0, \Throwable $previous = null)
public function __construct(string $limiterClass, int $code = 0, ?\Throwable $previous = null)
{
parent::__construct(sprintf('Reserving tokens is not supported by "%s".', $limiterClass), $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion LimiterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface LimiterInterface
* @throws ReserveNotSupportedException if this limiter implementation doesn't support reserving tokens
* @throws \InvalidArgumentException if $tokens is larger than the maximum burst size
*/
public function reserve(int $tokens = 1, float $maxTime = null): Reservation;
public function reserve(int $tokens = 1, ?float $maxTime = null): Reservation;

/**
* Use this method if you intend to drop if the required number
Expand Down
4 changes: 2 additions & 2 deletions Policy/FixedWindowLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class FixedWindowLimiter implements LimiterInterface
private int $limit;
private int $interval;

public function __construct(string $id, int $limit, \DateInterval $interval, StorageInterface $storage, LockInterface $lock = null)
public function __construct(string $id, int $limit, \DateInterval $interval, StorageInterface $storage, ?LockInterface $lock = null)
{
if ($limit < 1) {
throw new \InvalidArgumentException(sprintf('Cannot set the limit of "%s" to 0, as that would never accept any hit.', __CLASS__));
Expand All @@ -42,7 +42,7 @@ public function __construct(string $id, int $limit, \DateInterval $interval, Sto
$this->interval = TimeUtil::dateIntervalToSeconds($interval);
}

public function reserve(int $tokens = 1, float $maxTime = null): Reservation
public function reserve(int $tokens = 1, ?float $maxTime = null): Reservation
{
if ($tokens > $this->limit) {
throw new \InvalidArgumentException(sprintf('Cannot reserve more tokens (%d) than the size of the rate limiter (%d).', $tokens, $this->limit));
Expand Down
2 changes: 1 addition & 1 deletion Policy/NoLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
final class NoLimiter implements LimiterInterface
{
public function reserve(int $tokens = 1, float $maxTime = null): Reservation
public function reserve(int $tokens = 1, ?float $maxTime = null): Reservation
{
return new Reservation(microtime(true), new RateLimit(\PHP_INT_MAX, new \DateTimeImmutable(), true, \PHP_INT_MAX));
}
Expand Down
4 changes: 2 additions & 2 deletions Policy/SlidingWindowLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class SlidingWindowLimiter implements LimiterInterface
private int $limit;
private int $interval;

public function __construct(string $id, int $limit, \DateInterval $interval, StorageInterface $storage, LockInterface $lock = null)
public function __construct(string $id, int $limit, \DateInterval $interval, StorageInterface $storage, ?LockInterface $lock = null)
{
$this->storage = $storage;
$this->lock = $lock;
Expand All @@ -46,7 +46,7 @@ public function __construct(string $id, int $limit, \DateInterval $interval, Sto
$this->interval = TimeUtil::dateIntervalToSeconds($interval);
}

public function reserve(int $tokens = 1, float $maxTime = null): Reservation
public function reserve(int $tokens = 1, ?float $maxTime = null): Reservation
{
if ($tokens > $this->limit) {
throw new \InvalidArgumentException(sprintf('Cannot reserve more tokens (%d) than the size of the rate limiter (%d).', $tokens, $this->limit));
Expand Down
2 changes: 1 addition & 1 deletion Policy/TokenBucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class TokenBucket implements LimiterStateInterface
* @param Rate $rate the fill rate and time of this bucket
* @param float|null $timer the current timer of the bucket, defaulting to microtime(true)
*/
public function __construct(string $id, int $initialTokens, Rate $rate, float $timer = null)
public function __construct(string $id, int $initialTokens, Rate $rate, ?float $timer = null)
{
if ($initialTokens < 1) {
throw new \InvalidArgumentException(sprintf('Cannot set the limit of "%s" to 0, as that would never accept any hit.', TokenBucketLimiter::class));
Expand Down
4 changes: 2 additions & 2 deletions Policy/TokenBucketLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class TokenBucketLimiter implements LimiterInterface
private int $maxBurst;
private Rate $rate;

public function __construct(string $id, int $maxBurst, Rate $rate, StorageInterface $storage, LockInterface $lock = null)
public function __construct(string $id, int $maxBurst, Rate $rate, StorageInterface $storage, ?LockInterface $lock = null)
{
$this->id = $id;
$this->maxBurst = $maxBurst;
Expand All @@ -50,7 +50,7 @@ public function __construct(string $id, int $maxBurst, Rate $rate, StorageInterf
* @throws MaxWaitDurationExceededException if $maxTime is set and the process needs to wait longer than its value (in seconds)
* @throws \InvalidArgumentException if $tokens is larger than the maximum burst size
*/
public function reserve(int $tokens = 1, float $maxTime = null): Reservation
public function reserve(int $tokens = 1, ?float $maxTime = null): Reservation
{
if ($tokens > $this->maxBurst) {
throw new \InvalidArgumentException(sprintf('Cannot reserve more tokens (%d) than the burst size of the rate limiter (%d).', $tokens, $this->maxBurst));
Expand Down
4 changes: 2 additions & 2 deletions Policy/Window.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class Window implements LimiterStateInterface
private int $maxSize;
private float $timer;

public function __construct(string $id, int $intervalInSeconds, int $windowSize, float $timer = null)
public function __construct(string $id, int $intervalInSeconds, int $windowSize, ?float $timer = null)
{
$this->id = $id;
$this->intervalInSeconds = $intervalInSeconds;
Expand All @@ -44,7 +44,7 @@ public function getExpirationTime(): ?int
return $this->intervalInSeconds;
}

public function add(int $hits = 1, float $now = null): void
public function add(int $hits = 1, ?float $now = null): void
{
$now ??= microtime(true);
if (($now - $this->timer) > $this->intervalInSeconds) {
Expand Down
4 changes: 2 additions & 2 deletions RateLimiterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class RateLimiterFactory
private StorageInterface $storage;
private ?LockFactory $lockFactory;

public function __construct(array $config, StorageInterface $storage, LockFactory $lockFactory = null)
public function __construct(array $config, StorageInterface $storage, ?LockFactory $lockFactory = null)
{
$this->storage = $storage;
$this->lockFactory = $lockFactory;
Expand All @@ -41,7 +41,7 @@ public function __construct(array $config, StorageInterface $storage, LockFactor
$this->config = $options->resolve($config);
}

public function create(string $key = null): LimiterInterface
public function create(?string $key = null): LimiterInterface
{
$id = $this->config['id'].'-'.$key;
$lock = $this->lockFactory?->createLock($id);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Policy/TokenBucketLimiterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function testBucketRefilledWithStrictFrequency()
}
}

private function createLimiter($initialTokens = 10, Rate $rate = null)
private function createLimiter($initialTokens = 10, ?Rate $rate = null)
{
return new TokenBucketLimiter('test', $initialTokens, $rate ?? Rate::perSecond(10), $this->storage);
}
Expand Down

0 comments on commit 05ac83c

Please sign in to comment.