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

CacheCounterStorage::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
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