Passed
Push — master ( 31c7b0...a544c9 )
by Alexander
01:28
created

SimpleContainer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 6 2
A __construct() 0 3 1
A has() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Test\Support\Container;
6
7
use Psr\Container\ContainerInterface;
8
use Yiisoft\Test\Support\Container\Exception\NotFoundException;
9
10
class SimpleContainer implements ContainerInterface
11
{
12
    private array $definitions;
13
14 5
    public function __construct(array $definitions = [])
15
    {
16 5
        $this->definitions = $definitions;
17 5
    }
18
19 2
    public function get($id)
20
    {
21 2
        if (!$this->has($id)) {
22 1
            throw new NotFoundException($id);
23
        }
24 1
        return $this->definitions[$id];
25
    }
26
27 5
    public function has($id)
28
    {
29 5
        return array_key_exists($id, $this->definitions);
30
    }
31
}
32