InMemoryStorage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Key\Storage;
6
7
use Damax\Bundle\ApiAuthBundle\Key\Key;
8
9
final class InMemoryStorage implements Reader
10
{
11
    private $data;
12
    private $ttl;
13
14
    public function __construct(array $data, int $ttl = 3600)
15
    {
16
        $this->data = $data;
17
        $this->ttl = $ttl;
18
    }
19
20
    public function has(string $key): bool
21
    {
22
        return (bool) array_search($key, $this->data);
23
    }
24
25
    public function get(string $key): Key
26
    {
27
        if (false === $identity = array_search($key, $this->data)) {
28
            throw new KeyNotFound();
29
        }
30
31
        return new Key($key, $identity, $this->ttl);
32
    }
33
}
34