Passed
Push — master ( 772c92...f3c67a )
by Evgeniy
01:14 queued 12s
created

KeyValue   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 26
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 3 1
A __construct() 0 3 1
A get() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI\Container;
6
7
use Cekta\DI\Exception\NotFound;
8
use Psr\Container\ContainerInterface;
9
10
class KeyValue implements ContainerInterface
11
{
12
    /**
13
     * @var array<string, mixed>
14
     */
15
    private $values;
16
17
    /**
18
     * @param array<string, mixed> $values
19
     */
20 24
    public function __construct(array $values)
21
    {
22 24
        $this->values = $values;
23 24
    }
24
25 15
    public function get($id)
26
    {
27 15
        if (!$this->has($id)) {
28 3
            throw new NotFound($id);
29
        }
30 12
        return $this->values[$id];
31
    }
32
33 18
    public function has($id): bool
34
    {
35 18
        return array_key_exists($id, $this->values);
36
    }
37
}
38