Completed
Push — master ( c18e2a...b8ddaa )
by Woody
05:03 queued 02:48
created

InjectorContainer::get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
crap 3
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 5
    public function __construct(Injector $injector)
17
    {
18 5
        $this->injector = $injector;
19 5
    }
20
21
    // ContainerInterface
22 3
    public function get($id)
23
    {
24 3
        if (false === $this->has($id)) {
25 1
            throw NotFoundException::classDoesNotExist($id);
26
        }
27
28
        try {
29 2
            return $this->injector->make($id);
30 1
        } catch (InjectorException $e) {
31 1
            throw ContainerException::couldNotMake($id, $e);
32
        }
33
    }
34
35
    // ContainerInterface
36 4
    public function has($id)
37
    {
38 4
        return class_exists($id);
39
    }
40
}
41