Injector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

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
/**
17
 * @see PackageInjector
18
 * @psalm-import-type AppName from Types
19
 * @psalm-import-type Context from Types
20
 * @psalm-import-type AppDir from Types
21
 */
22
final class Injector
23
{
24
    /** @codeCoverageIgnore */
25
    private function __construct()
26
    {
27
    }
28
29
    /**
30
     * @param AppName $appName
0 ignored issues
show
Bug introduced by
The type BEAR\Package\AppName was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     * @param Context $context
32
     * @param AppDir  $appDir
0 ignored issues
show
Bug introduced by
The type BEAR\Package\AppDir was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
     */
34
    public static function getInstance(string $appName, string $context, string $appDir, CacheInterface|null $cache = null): InjectorInterface
35
    {
36
        $meta = new Meta($appName, $context, $appDir);
37
        $cacheNamespace = str_replace('\\', '_', $appName) . $context;
38
        $cache ??= (new LocalCacheProvider($meta->tmpDir . '/injector', $cacheNamespace))->get();
39
40
        return PackageInjector::getInstance($meta, $context, $cache);
41
    }
42
43
    /**
44
     * @param AppName $appName
45
     * @param Context $context
46
     * @param AppDir  $appDir
47
     */
48
    public static function getOverrideInstance(string $appName, string $context, string $appDir, AbstractModule $overrideModule): InjectorInterface
49
    {
50
        return PackageInjector::factory(new Meta($appName, $context, $appDir), $context, $overrideModule);
51
    }
52
}
53