Passed
Push — master ( 4ab40f...089bf1 )
by Timo
03:39
created

ArrayAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 8 2
A get() 0 3 1
1
<?php
2
3
namespace hamburgscleanest\GuzzleAdvancedThrottle\Cache\Adapters;
4
5
use DateTime;
6
use hamburgscleanest\GuzzleAdvancedThrottle\Cache\Interfaces\StorageInterface;
7
use hamburgscleanest\GuzzleAdvancedThrottle\RequestInfo;
8
9
/**
10
 * Class ArrayAdapter
11
 * @package hamburgscleanest\GuzzleAdvancedThrottle\Cache\Adapters
12
 */
13
class ArrayAdapter implements StorageInterface
14
{
15
16
    /** @var array */
17
    private $_storage = [];
18
19
    /**
20
     * @param string $host
21
     * @param string $key
22
     * @param int $requestCount
23
     * @param \DateTime $expiresAt
24
     * @param int $remainingSeconds
25
     */
26 3
    public function save(string $host, string $key, int $requestCount, DateTime $expiresAt, int $remainingSeconds) : void
27
    {
28 3
        if (!isset($this->_storage[$host]))
29
        {
30 3
            $this->_storage[$host] = [];
31
        }
32
33 3
        $this->_storage[$host][$key] = RequestInfo::create($requestCount, $expiresAt->getTimestamp(), $remainingSeconds);
34 3
    }
35
36
    /**
37
     * @param string $host
38
     * @param string $key
39
     * @return RequestInfo|null
40
     */
41 5
    public function get(string $host, string $key) : ? RequestInfo
42
    {
43 5
        return $this->_storage[$host][$key] ?? null;
44
    }
45
}