Passed
Pull Request — master (#203)
by
unknown
12:43
created

CacheStorage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCounterValue() 0 3 1
A hasCounterValue() 0 3 1
A setCounterValue() 0 3 1
A __construct() 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
final class CacheStorage implements StorageInterface
10
{
11
    private CacheInterface $cache;
12
13
    public function __construct(CacheInterface $cache)
14
    {
15
        $this->cache = $cache;
16
    }
17
18
    public function getCounterValue(string $id): int
19
    {
20
        return $this->cache->get($id, 0);
21
    }
22
23
    public function setCounterValue(string $id, int $value, int $interval): void
24
    {
25
        $this->cache->set($id, $value, $interval);
26
    }
27
28
    public function hasCounterValue(string $id): bool
29
    {
30
        return $this->cache->has($id);
31
    }
32
}
33