Container   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 47
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A set() 0 4 1
A remove() 0 6 2
A has() 0 4 1
1
<?php
2
declare(strict_types = 1);
3
namespace Zewa;
4
5
use Interop\Container\ContainerInterface;
6
use Zewa\Exception\LookupException;
7
8
class Container implements ContainerInterface
9
{
10
    /**
11
     * @var array
12
     */
13
    private $container = [];
14
15
    /**
16
     * Add an object to the container
17
     *
18
     * @param string $key The name of a service to set in the container
19
     * @param mixed $value A closure of object representing a serive
20
     *
21
     * @return $this
22
     */
23 39
    public function set($key, $value = null)
24
    {
25 39
        $this->container[$key] = $value;
26 39
    }
27
28 1
    public function remove($key)
29
    {
30 1
        if ($this->has($key)) {
31 1
            unset($this->container[$key]);
32
        }
33 1
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 40
    public function get($key)
39
    {
40 40
        if (! $this->has($key)) {
41 1
            throw new LookupException('Container doesn\'t exist.');
42
        }
43
44 39
        return $this->container[$key];
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 40
    public function has($key)
51
    {
52 40
        return array_key_exists($key, $this->container);
53
    }
54
}
55