Skip to content

Commit 67e82ca

Browse files
authored
Change Memory Store to static (#25)
* change memory store to static * wip * run cs fixer
1 parent 092f3b2 commit 67e82ca

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/Stores/MemoryStore.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ class MemoryStore implements RateLimitStore
1313
*
1414
* @var array<string, mixed>
1515
*/
16-
protected array $store = [];
16+
protected static array $store = [];
1717

1818
/**
1919
* Get a rate limit from the store
2020
*/
2121
public function get(string $key): ?string
2222
{
23-
return $this->store[$key] ?? null;
23+
return self::$store[$key] ?? null;
2424
}
2525

2626
/**
2727
* Set the rate limit into the store
2828
*/
2929
public function set(string $key, string $value, int $ttl): bool
3030
{
31-
$this->store[$key] = $value;
31+
self::$store[$key] = $value;
3232

3333
return true;
3434
}
@@ -40,6 +40,14 @@ public function set(string $key, string $value, int $ttl): bool
4040
*/
4141
public function getStore(): array
4242
{
43-
return $this->store;
43+
return self::$store;
44+
}
45+
46+
/**
47+
* Clear the store
48+
*/
49+
public static function clear(): void
50+
{
51+
self::$store = [];
4452
}
4553
}

tests/Pest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
|
1414
*/
1515

16+
use Saloon\RateLimitPlugin\Stores\MemoryStore;
1617
use Orchestra\Testbench\TestCase as LaravelTestCase;
1718

18-
uses(LaravelTestCase::class)->in('./Laravel');
19+
uses(LaravelTestCase::class)
20+
->beforeEach(fn () => MemoryStore::clear())
21+
->in('./Laravel');
22+
23+
uses()
24+
->beforeEach(fn () => MemoryStore::clear())
25+
->afterEach(fn () => MemoryStore::clear())
26+
->in('./');
1927

2028
/*
2129
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)