ChainStorage::has()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
rs 10
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 ChainStorage implements Reader
10
{
11
    /**
12
     * @var Reader[]
13
     */
14
    private $items = [];
15
16
    public function __construct(array $items = [])
17
    {
18
        foreach ($items as $item) {
19
            $this->addStorage($item);
20
        }
21
    }
22
23
    public function addStorage(Reader $storage): void
24
    {
25
        $this->items[] = $storage;
26
    }
27
28
    public function has(string $key): bool
29
    {
30
        foreach ($this->items as $storage) {
31
            if ($storage->has($key)) {
32
                return true;
33
            }
34
        }
35
36
        return false;
37
    }
38
39
    public function get(string $key): Key
40
    {
41
        foreach ($this->items as $storage) {
42
            if ($storage->has($key)) {
43
                return $storage->get($key);
44
            }
45
        }
46
47
        throw new KeyNotFound();
48
    }
49
}
50