Completed
Push — master ( a2f223...c69a80 )
by
unknown
30s
created

Container::has()   A

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 Zewa\Exception\LookupException;
6
7
class Container
8
{
9
    /**
10
     * @var array
11
     */
12
    private $container = [];
13
14
    /**
15
     * Add an object to the container
16
     *
17
     * @param string $key The name of a service to set in the container
18
     * @param mixed $value A closure of object representing a serive
19
     * @return $this
20
     */
21 8
    public function set($key, $value = null)
22
    {
23 8
        $this->container[$key] = $value;
24 8
    }
25
26
    /**
27
     * @param $key
28
     * @return mixed
29
     * @throws LookupException
30
     */
31 8
    public function get($key)
32
    {
33 8
        if (!$this->has($key)) {
34
            throw new LookupException('Container doesn\'t exist.');
35
        }
36
37 8
        return $this->container[$key];
38
    }
39
40
    /**
41
     * @param $key
42
     * @return bool
43
     */
44 8
    public function has($key)
45
    {
46 8
        return array_key_exists($key, $this->container);
47
    }
48
}
49