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

ArrayCache   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

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