InjectorContainer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 39
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 12 3
A has() 0 4 3
A hasReference() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Northwoods\Container;
5
6
use Auryn\Injector;
7
use Auryn\InjectorException;
8
use Psr\Container\ContainerInterface;
9
use Interop\Container\ContainerInterface as InteropContainerInterface;
10
11
class InjectorContainer implements ContainerInterface, InteropContainerInterface
12
{
13
    const I_ALL = 31;
14
15
    /** @var Injector */
16
    private $injector;
17
18 244
    public function __construct(Injector $injector)
19
    {
20 244
        $this->injector = $injector;
21 244
    }
22
23
    // ContainerInterface
24 238
    public function get($id)
25
    {
26 238
        if ($this->has($id) === false) {
27 1
            throw NotFoundException::classDoesNotExist($id);
28
        }
29
30
        try {
31 237
            return $this->injector->make($id);
32 95
        } catch (InjectorException $e) {
0 ignored issues
show
Bug introduced by
The class Auryn\InjectorException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
33 5
            throw ContainerException::couldNotMake($id, $e);
34
        }
35
    }
36
37
    // ContainerInterface
38 239
    public function has($id)
39
    {
40 239
        return is_string($id) && (class_exists($id) || $this->hasReference($id));
41
    }
42
43 220
    private function hasReference(string $id): bool
44
    {
45
        // https://github.com/rdlowrey/auryn/issues/157
46 220
        $details = $this->injector->inspect($id, self::I_ALL);
47 220
        return (bool) array_filter($details);
48
    }
49
}
50