Completed
Push — master ( 4fc007...9eb98f )
by John
02:50
created

APIKeyCachePoolThrottle::deriveCacheKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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