InjectorContainer::hasReference()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

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 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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