KeyContainer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addKey() 0 4 1
A tagKey() 0 4 1
A get() 0 8 2
A has() 0 4 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