Container::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
namespace DevOp\Core;
3
4
use Psr\Container\ContainerInterface;
5
use DevOp\Core\Exception\NotFoundException;
6
use DevOp\Core\Exception\ContainerException;
7
8
class Container implements ContainerInterface
9
{
10
11
    /**
12
     * @var \ArrayObject
13
     */
14
    private $services;
15
16
    /**
17
     * @param int|string $id
18
     * @return int|string|array|object
19
     * @throws NotFoundException
20
     */
21 6
    public function get($id)
22
    {
23 6
        if ($this->has($id)) {
24 4
            return $this->services[$id];
25
        }
26 2
        throw new NotFoundException();
27
    }
28
29
    /**
30
     * @param int|string $id
31
     * @return boolean
32
     */
33 8
    public function has($id)
34
    {
35 8
        if (isset($this->services[$id])) {
36 6
            return true;
37
        }
38 8
        return null;
39
    }
40
41
    /**
42
     * @param int|string $id
43
     * @param mixed $arguments
44
     * @throws ContainerException
45
     */
46 6
    public function add($id, $arguments)
47
    {
48 6
        if ($this->has($id)) {
49 2
            throw new ContainerException("Service with name {$id} allready registered.");
50
        }
51
52 6
        $this->services[$id] = $arguments;
53 6
    }
54
}
55