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

ThemeProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 30
ccs 12
cts 14
cp 0.8571
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 14 2
A __construct() 0 5 1
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