Passed
Pull Request — master (#122)
by Sergei
12:04
created

ApplicationViewInjection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 20
dl 0
loc 44
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetaTags() 0 7 1
A getLinkTags() 0 7 1
A getLayoutParams() 0 6 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\ViewRenderer;
6
7
use Yiisoft\Router\UrlMatcherInterface;
8
use Yiisoft\Yii\Web\User\User;
9
10
class ApplicationViewInjection implements
11
    LayoutParamsInjectionInterface,
12
    MetaTagsInjectionInterface,
13
    LinkTagsInjectionInterface
14
{
15
16
    private User $user;
17
    private UrlMatcherInterface $urlMatcher;
18
19
    public function __construct(
20
        User $user,
21
        UrlMatcherInterface $urlMatcher
22
    ) {
23
        $this->user = $user;
24
        $this->urlMatcher = $urlMatcher;
25
    }
26
27
    public function getLayoutParams(): array
28
    {
29
        return [
30
            'user' => $this->user->getIdentity(),
31
            'currentUrl' => (string)$this->urlMatcher->getLastMatchedRequest()->getUri(),
32
            'brandLabel' => 'Yii Demo',
33
        ];
34
    }
35
36
    public function getMetaTags(): array
37
    {
38
        return [
39
            [
40
                '__key' => 'generator',
41
                'name' => 'generator',
42
                'value' => 'Yii',
43
            ],
44
        ];
45
    }
46
47
    public function getLinkTags(): array
48
    {
49
        return [
50
            [
51
                '__key' => 'favicon',
52
                'name' => 'icon',
53
                'value' => 'favicon.ico',
54
            ],
55
        ];
56
    }
57
}
58