Completed
Push — master ( 4fc007...9eb98f )
by John
02:50
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\Throttle;
3
4
use LunixREST\APIRequest\APIRequest;
5
use Psr\Cache\CacheItemPoolInterface;
6
7
class APIKeyCachePoolThrottle extends CachePoolThrottle
8
{
9
    /**
10
     * @var string
11
     */
12
    private $keyPrefix;
13
14
    /**
15
     * APIKeyCachePoolThrottle constructor.
16
     * @param CacheItemPoolInterface $cacheItemPool
17
     * @param int $limit
18
     * @param int $perXSeconds
19
     * @param string $keyPrefix
20
     */
21 8
    public function __construct(CacheItemPoolInterface $cacheItemPool, $limit = 60, $perXSeconds = 60, $keyPrefix = '')
22
    {
23 8
        parent::__construct($cacheItemPool, $limit, $perXSeconds);
24 8
        $this->keyPrefix = $keyPrefix;
25 8
    }
26
27
    /**
28
     * @param APIRequest $request
29
     * @return string
30
     */
31 7
    protected function deriveCacheKey(APIRequest $request): string
32
    {
33 7
        return $this->keyPrefix . $request->getApiKey();
34
    }
35
}
36