KeyContainer::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Carnage\EncryptedColumn\Container;
4
5
use Carnage\EncryptedColumn\ValueObject\Key;
6
use Psr\Container\ContainerInterface;
7
8
final class KeyContainer implements ContainerInterface
9
{
10
    /**
11
     * @var array
12
     */
13
    private $keys = [];
14
15
    public function addKey(Key $key)
16
    {
17
        $this->keys[$key->getIdentifier()->toString()] = $key;
18
    }
19
20
    public function tagKey($tag, $id)
21
    {
22
        $this->keys[$tag] = $this->keys[$id];
23
    }
24
25
    public function get($id)
26
    {
27
        if (!$this->has($id)) {
28
            throw NotFoundException::serviceNotFoundInContainer($id, $this->keys);
29
        }
30
31
        return $this->keys[$id];
32
    }
33
34
    public function has($id): bool
35
    {
36
        return isset($this->keys[$id]);
37
    }
38
}
39