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

InjectorContainer::hasAlias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
cc 1
eloc 4
nc 1
nop 1
crap 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