ArrayCache::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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