Injector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 3
eloc 5
c 4
b 1
f 0
dl 0
loc 19
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getOverrideInstance() 0 3 1
A getInstance() 0 7 1
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package;
6
7
use BEAR\AppMeta\Meta;
8
use BEAR\Package\Injector\PackageInjector;
9
use Ray\Di\AbstractModule;
10
use Ray\Di\InjectorInterface;
11
use Ray\PsrCacheModule\LocalCacheProvider;
12
use Symfony\Contracts\Cache\CacheInterface;
13
14
use function str_replace;
15
16
/** @see PackageInjector */
17
final class Injector
18
{
19
    /** @codeCoverageIgnore */
20
    private function __construct()
21
    {
22
    }
23
24
    public static function getInstance(string $appName, string $context, string $appDir, CacheInterface|null $cache = null): InjectorInterface
25
    {
26
        $meta = new Meta($appName, $context, $appDir);
27
        $cacheNamespace = str_replace('\\', '_', $appName) . $context;
28
        $cache ??= (new LocalCacheProvider($meta->tmpDir . '/injector', $cacheNamespace))->get();
29
30
        return PackageInjector::getInstance($meta, $context, $cache);
31
    }
32
33
    public static function getOverrideInstance(string $appName, string $context, string $appDir, AbstractModule $overrideModule): InjectorInterface
34
    {
35
        return PackageInjector::factory(new Meta($appName, $context, $appDir), $context, $overrideModule);
36
    }
37
}
38