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

KeyContainer::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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