Passed
Push — master ( 2e0dfd...c3d764 )
by Alexander
02:16
created

ThemeProvider::register()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0438

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 14
ccs 7
cts 9
cp 0.7778
crap 2.0438
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Provider;
6
7
use Yiisoft\Aliases\Aliases;
8
use Yiisoft\Di\Container;
9
use Yiisoft\Di\Support\ServiceProvider;
10
use Yiisoft\View\Theme;
11
12
final class ThemeProvider extends ServiceProvider
13
{
14
    private array $pathMap;
15
    private string $basePath;
16
    private string $baseUrl;
17
18 8
    public function __construct(array $pathMap = [], string $basePath = '', string $baseUrl = '')
19
    {
20 8
        $this->pathMap = $pathMap;
21 8
        $this->basePath = $basePath;
22 8
        $this->baseUrl = $baseUrl;
23 8
    }
24
25
    /**
26
     * @suppress PhanAccessMethodProtected
27
     */
28 8
    public function register(Container $container): void
29
    {
30 8
        $aliases = $container->get(Aliases::class);
31
32 8
        $pathMap = $this->pathMap;
33 8
        foreach ($pathMap as $key => $value) {
34
            $this->pathMap = [
35
                $aliases->get($key) => $aliases->get($value)
36
            ];
37
        }
38
39 8
        $container->set(
40 8
            Theme::class,
41 8
            fn () => new Theme($this->pathMap, $this->basePath, $this->baseUrl)
42 8
        );
43 8
    }
44
}
45