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

CacheStorage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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