Passed
Pull Request — master (#122)
by
unknown
10:47
created

UserInjection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getParams() 0 3 1
A withParameter() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\ViewRenderer;
6
7
use Yiisoft\Yii\Web\User\User;
8
9
class UserInjection implements InjectionInterface
10
{
11
    public const DEFAULT_PARAMETER = 'user';
12
13
    private User $user;
14
15
    private string $parameter = self::DEFAULT_PARAMETER;
16
17
    public function __construct(User $user)
18
    {
19
        $this->user = $user;
20
    }
21
22
    public function withParameter(string $parameter): self
23
    {
24
        $clone = clone $this;
25
        $clone->parameter = $parameter;
26
        return $clone;
27
    }
28
29
    public function getParams(): array
30
    {
31
        return [$this->parameter => $this->user->getIdentity()];
32
    }
33
}
34