Passed
Pull Request — master (#6)
by Chris
05:44
created

KeyContainer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 31
ccs 11
cts 12
cp 0.9167
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
     */
12
    private $keys;
13
14
15 6
    public function addKey(Key $key)
16
    {
17 6
        $this->keys[$key->getIdentifier()->toString()] = $key;
18 6
    }
19
20 6
    public function tagKey($tag, $id)
21
    {
22 6
        $this->keys[$tag] = $this->keys[$id];
23 6
    }
24
25 7
    public function get($id)
26
    {
27 7
        if (!$this->has($id)) {
28
            throw NotFoundException::serviceNotFoundInContainer($id, $this->keys);
29
        }
30
31 7
        return $this->keys[$id];
32
    }
33
34 7
    public function has($id): bool
35
    {
36 7
        return isset($this->keys[$id]);
37
    }
38
}
39