Skip to content

Commit 4487a32

Browse files
authored
Merge pull request #18 from sirikkoster/v2
Fix deprecation warnings and modifications for php8.4
2 parents 651be17 + 949d9ec commit 4487a32

File tree

7 files changed

+22
-19
lines changed

7 files changed

+22
-19
lines changed

.github/FUNDING

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ko_fi: sammyjo20
1+
github: sammyjo20

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup PHP
1919
uses: shivammathur/setup-php@v2
2020
with:
21-
php-version: '8.1'
21+
php-version: '8.4'
2222
coverage: none
2323

2424
- name: Install composer dependencies

.github/workflows/redis-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: true
1919
matrix:
2020
os: [ ubuntu-latest ]
21-
php: [ 8.1, 8.2 ]
21+
php: [ 8.1, 8.2, 8.3, 8.4 ]
2222
stability: [ prefer-lowest, prefer-stable ]
2323
services:
2424
# Label used to access the service container
@@ -39,7 +39,7 @@ jobs:
3939

4040
steps:
4141
- name: Checkout code
42-
uses: actions/checkout@v3
42+
uses: actions/checkout@v4
4343

4444
- name: Setup PHP
4545
uses: shivammathur/setup-php@v2

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ jobs:
1818
fail-fast: true
1919
matrix:
2020
os: [ ubuntu-latest, windows-latest ]
21-
php: [ 8.1, 8.2 ]
21+
php: [ 8.1, 8.2, 8.3, 8.4 ]
2222
stability: [ prefer-lowest, prefer-stable ]
2323

2424
name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
2525

2626
steps:
2727
- name: Checkout code
28-
uses: actions/checkout@v3
28+
uses: actions/checkout@v4
2929

3030
- name: Setup PHP
3131
uses: shivammathur/setup-php@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# Caches, externally stored stuff, etc
1515
.php-cs-fixer.cache
1616
.phpunit.result.cache
17+
.phpunit.cache
1718
tests/Fixtures/Saloon
1819

1920
# environments/configs

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"orchestra/testbench": "^8.5"
2727
},
2828
"minimum-stability": "stable",
29+
"prefer-stable": true,
2930
"autoload": {
3031
"psr-4": {
3132
"Saloon\\RateLimitPlugin\\": "src/",

src/Limit.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Saloon\RateLimitPlugin;
66

7-
use Closure;
87
use DateInterval;
98
use DateTimeImmutable;
109
use Saloon\Http\Response;
@@ -40,7 +39,7 @@ class Limit
4039
/**
4140
* The threshold that should be used when determining if a limit has been reached
4241
*
43-
* Must be between 0 and 1. For example if you want the limiter to kick in at 85%
42+
* Must be between 0 and 1. For example, if you want the limiter to kick in at 85%
4443
* you must set the threshold to 0.85
4544
*/
4645
protected float $threshold = 1;
@@ -58,8 +57,10 @@ class Limit
5857

5958
/**
6059
* Custom response handler
60+
*
61+
* @var null|callable(): mixed
6162
*/
62-
protected ?Closure $responseHandler = null;
63+
protected $responseHandler = null;
6364

6465
/**
6566
* Determines if we should sleep or not
@@ -69,15 +70,15 @@ class Limit
6970
/**
7071
* @param (callable(): mixed)|null $responseHandler
7172
*/
72-
final public function __construct(int $allow, float $threshold = 1, callable $responseHandler = null)
73+
final public function __construct(int $allow, float $threshold = 1, ?callable $responseHandler = null)
7374
{
7475
$this->allow = $allow;
7576
$this->threshold = $threshold;
76-
$this->responseHandler = isset($responseHandler) ? $responseHandler(...) : null;
77+
$this->responseHandler = $responseHandler;
7778
}
7879

7980
/**
80-
* Construct a limiter's allow and threshold
81+
* Construct a limiter's allowing and threshold
8182
*/
8283
public static function allow(int $requests, float $threshold = 1): static
8384
{
@@ -89,7 +90,7 @@ public static function allow(int $requests, float $threshold = 1): static
8990
*/
9091
public static function custom(callable $responseHandler): static
9192
{
92-
return (new static(1, 1, $responseHandler(...)))->everySeconds(60, 'custom');
93+
return (new static(1, 1, $responseHandler))->everySeconds(60, 'custom');
9394
}
9495

9596
/**
@@ -123,7 +124,7 @@ public function hit(int $amount = 1): static
123124
/**
124125
* Set the limit as exceeded
125126
*/
126-
public function exceeded(int $releaseInSeconds = null): void
127+
public function exceeded(?int $releaseInSeconds = null): void
127128
{
128129
$this->exceeded = true;
129130

@@ -281,7 +282,7 @@ public function handleResponse(Response $response): void
281282
*
282283
* @return $this
283284
* @throws \JsonException
284-
* @throws \Saloon\RateLimitPlugin\Exceptions\LimitException
285+
* @throws LimitException
285286
*/
286287
public function update(RateLimitStore $store): static
287288
{
@@ -316,14 +317,14 @@ public function update(RateLimitStore $store): static
316317
return $this;
317318
}
318319

319-
// If our expiry hasn't passed, yet then we'll set the expiry timestamp
320-
// and, we'll also update the hits so the current instance has the
320+
// If our expiry hasn't passed yet, then we'll set the expiry timestamp,
321+
// and we'll also update the hits so the current instance has the
321322
// number of previous hits.
322323

323324
$this->setExpiryTimestamp($expiry);
324325
$this->hit($hits);
325326

326-
// If this is a fromResponse limiter then we should apply the "allow" which will
327+
// If this is a fromResponse limiter, then we should apply the "allow" which will
327328
// be useful to check if we have reached our rate limit
328329

329330
if ($this->usesResponse()) {
@@ -338,7 +339,7 @@ public function update(RateLimitStore $store): static
338339
*
339340
* @return $this
340341
* @throws \JsonException
341-
* @throws \Saloon\RateLimitPlugin\Exceptions\LimitException
342+
* @throws LimitException
342343
*/
343344
public function save(RateLimitStore $store, int $resetHits = 1): static
344345
{

0 commit comments

Comments
 (0)