Completed
Push — master ( 0a059e...292010 )
by John
02:21
created

APIKeyCachePoolThrottle   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 29
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A deriveCacheKey() 0 4 1
1
<?php
2
namespace LunixREST\Server\Throttle;
3
4
use LunixREST\Server\APIRequest\APIRequest;
5
use Psr\Cache\CacheItemPoolInterface;
6
7
/**
8
 * Class APIKeyCachePoolThrottle
9
 * @package LunixREST\Server\Throttle
10
 */
11
class APIKeyCachePoolThrottle extends CachePoolThrottle
12
{
13
    /**
14
     * @var string
15
     */
16
    private $keyPrefix;
17
18
    /**
19
     * APIKeyCachePoolThrottle constructor.
20
     * @param CacheItemPoolInterface $cacheItemPool
21
     * @param int $limit
22
     * @param int $perXSeconds
23
     * @param string $keyPrefix
24
     */
25 8
    public function __construct(CacheItemPoolInterface $cacheItemPool, $limit = 60, $perXSeconds = 60, $keyPrefix = '')
26
    {
27 8
        parent::__construct($cacheItemPool, $limit, $perXSeconds);
28 8
        $this->keyPrefix = $keyPrefix;
29 8
    }
30
31
    /**
32
     * @param APIRequest $request
33
     * @return string
34
     */
35 7
    protected function deriveCacheKey(APIRequest $request): string
36
    {
37 7
        return $this->keyPrefix . $request->getApiKey();
38
    }
39
}
40