Container::has()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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