Passed
Push — master ( f3c67a...8e7fe7 )
by Evgeniy
14:18 queued 10s
created

KeyValue::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI\Strategy;
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
    public function __construct(array $values)
21
    {
22
        $this->values = $values;
23
    }
24
25
    public function get($id)
26
    {
27
        if (!$this->has($id)) {
28
            throw new NotFound($id);
29
        }
30
        return $this->values[$id];
31
    }
32
33
    public function has($id): bool
34
    {
35
        return array_key_exists($id, $this->values);
36
    }
37
}
38