Passed
Pull Request — master (#203)
by Alexander
02:04
created

CacheCounterStorage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 3 1
A has() 0 3 1
A __construct() 0 3 1
A get() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Web\RateLimiter;
6
7
use Psr\SimpleCache\CacheInterface;
8
9
/**
10
 * Stores counter values in cache
11
 */
12
final class CacheCounterStorage implements CounterStorageInterface
13
{
14
    private CacheInterface $cache;
15
16
    public function __construct(CacheInterface $cache)
17
    {
18
        $this->cache = $cache;
19
    }
20
21
    public function get(string $id): int
22
    {
23
        return $this->cache->get($id, 0);
24
    }
25
26
    public function set(string $id, int $value, int $interval): void
27
    {
28
        $this->cache->set($id, $value, $interval);
29
    }
30
31
    public function has(string $id): bool
32
    {
33
        return $this->cache->has($id);
34
    }
35
}
36