Completed
Push — master ( 1ac25e...0210cc )
by Woody
14s
created

InjectorContainer::hasReference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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
    const I_ALL = 31;
12
13
    /**
14
     * @var Injector
15
     */
16
    private $injector;
17
18 7
    public function __construct(Injector $injector)
19
    {
20 7
        $this->injector = $injector;
21 7
    }
22
23
    // ContainerInterface
24 4
    public function get($id)
25
    {
26 4
        if (false === $this->has($id)) {
27 1
            throw NotFoundException::classDoesNotExist($id);
28
        }
29
30
        try {
31 3
            return $this->injector->make($id);
32 1
        } catch (InjectorException $e) {
33 1
            throw ContainerException::couldNotMake($id, $e);
34
        }
35
    }
36
37
    // ContainerInterface
38 5
    public function has($id)
39
    {
40 5
        return class_exists($id) || $this->hasReference($id);
41
    }
42
43
    /**
44
     * Check the injector has a reference
45
     *
46
     * @param string $id
47
     *
48
     * @return bool
49
     */
50 3
    private function hasReference($id)
51
    {
52
        // https://github.com/rdlowrey/auryn/issues/157
53 3
        $details = $this->injector->inspect($id, self::I_ALL);
54 3
        return (bool) array_filter($details);
55
    }
56
}
57