Completed
Push — master ( 4fbf79...d99765 )
by Woody
12s
created

InjectorContainer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 47
rs 10
c 0
b 0
f 0
ccs 15
cts 15
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 12 3
A has() 0 4 2
A hasAlias() 0 7 1
1
<?php
2
3
namespace Northwoods\Container;
4
5
use Auryn\Injector;
6
use Auryn\InjectorException;
7
use Psr\Container\ContainerInterface;
8
9
class InjectorContainer implements ContainerInterface
10
{
11
    /**
12
     * @var Injector
13
     */
14
    private $injector;
15
16 6
    public function __construct(Injector $injector)
17
    {
18 6
        $this->injector = $injector;
19 6
    }
20
21
    // ContainerInterface
22 4
    public function get($id)
23
    {
24 4
        if (false === $this->has($id)) {
25 1
            throw NotFoundException::classDoesNotExist($id);
26
        }
27
28
        try {
29 3
            return $this->injector->make($id);
30 1
        } catch (InjectorException $e) {
31 1
            throw ContainerException::couldNotMake($id, $e);
32
        }
33
    }
34
35
    // ContainerInterface
36 5
    public function has($id)
37
    {
38 5
        return class_exists($id) || $this->hasAlias($id);
39
    }
40
41
    /**
42
     * Check the injector has an alias
43
     *
44
     * @param string $id
45
     *
46
     * @return bool
47
     */
48 3
    private function hasAlias($id)
49
    {
50 3
        $type = Injector::I_ALIASES;
51 3
        $details = $this->injector->inspect($id, $type);
52
53 3
        return !empty($details[$type][$id]);
54
    }
55
}
56