Passed
Push — master ( 705f9d...6814fe )
by Zlatin
02:30
created

Container   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 45
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 7 2
A has() 0 6 2
A get() 0 6 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 9
    public function get($id)
22
    {
23 9
        if ($this->has($id)) {
24 6
            return $this->services[$id];
25
        }
26 3
        throw new NotFoundException();
27
    }
28
29
    /**
30
     * @param int|string $id
31
     * @return boolean
32
     */
33 12
    public function has($id)
34
    {
35 12
        if (isset($this->services[$id])) {
36 9
            return true;
37
        }
38 12
        return null;
39
    }
40
41
    /**
42
     * @param string $id
43
     * @param id|string|array|object $arguments
0 ignored issues
show
Bug introduced by
The type DevOp\Core\id was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
     * @throws ContainerException
45
     */
46 9
    public function add($id, $arguments)
47
    {
48 9
        if ($this->has($id)) {
49 3
            throw new ContainerException("Service with name {$id} allready registered.");
50
        }
51
52 9
        $this->services[$id] = $arguments;
53 9
    }
54
}
55