Completed
Push — master ( 7353e9...0c9da4 )
by BENOIT
01:14
created

ArrayAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasCounter() 0 4 1
A getCounter() 0 4 1
A saveCounter() 0 4 1
A deleteCounter() 0 4 1
1
<?php
2
3
namespace BenTools\GuzzleHttp\Middleware\Storage\Adapter;
4
5
use BenTools\GuzzleHttp\Middleware\Storage\Counter;
6
use BenTools\GuzzleHttp\Middleware\Storage\ThrottleStorageInterface;
7
8
class ArrayAdapter implements ThrottleStorageInterface
9
{
10
11
    private $storage = [];
12
13
    /**
14
     * @inheritDoc
15
     */
16
    public function hasCounter(string $storageKey): bool
17
    {
18
        return isset($this->storage[$storageKey]);
19
    }
20
21
    /**
22
     * @inheritDoc
23
     */
24
    public function getCounter(string $storageKey)
25
    {
26
        return $this->storage[$storageKey] ?? null;
27
    }
28
29
    /**
30
     * @inheritDoc
31
     */
32
    public function saveCounter(string $storageKey, Counter $counter, float $ttl = null)
33
    {
34
        $this->storage[$storageKey] = $counter;
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40
    public function deleteCounter(string $storageKey)
41
    {
42
        unset($this->storage[$storageKey]);
43
    }
44
}
45