Passed
Push — master ( ba4ca1...142814 )
by Evgeniy
58s queued 11s
created

KeyValue::stringToType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI\Provider;
6
7
use Cekta\DI\Provider\Exception\NotFound;
8
use Cekta\DI\ProviderInterface;
9
10
class KeyValue implements ProviderInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $values;
16
17 24
    public function __construct(array $values)
18
    {
19 24
        $this->values = $values;
20 24
    }
21
22 12
    public function provide(string $id)
23
    {
24 12
        if (!$this->canProvide($id)) {
25 3
            throw new NotFound($id);
26
        }
27 9
        return $this->values[$id];
28
    }
29
30 15
    public function canProvide(string $id): bool
31
    {
32 15
        return array_key_exists($id, $this->values);
33
    }
34
}
35