Total Complexity | 6 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Coverage | 94.12% |
Changes | 0 |
1 | <?php |
||
25 | class Auth |
||
26 | { |
||
27 | use Options; |
||
28 | |||
29 | /** |
||
30 | * @var IdentityInterface Instance of EntityInterface |
||
31 | */ |
||
32 | protected $identity; |
||
33 | |||
34 | /** |
||
35 | * Setup identity |
||
36 | * |
||
37 | * @param IdentityInterface $identity |
||
38 | * |
||
39 | * @return void |
||
40 | */ |
||
41 | 3 | public function setIdentity(IdentityInterface $identity): void |
|
53 | 3 | } |
|
54 | |||
55 | /** |
||
56 | * Return identity if user agent is correct |
||
57 | * |
||
58 | * @return IdentityInterface|null |
||
59 | */ |
||
60 | 9 | public function getIdentity(): ?IdentityInterface |
|
61 | { |
||
62 | 9 | if (!$this->identity) { |
|
63 | // check user agent |
||
64 | 6 | if (Session::get('auth:agent') === Request::getServer('HTTP_USER_AGENT')) { |
|
65 | 5 | $this->identity = Session::get('auth:identity'); |
|
66 | } else { |
||
67 | 1 | $this->clearIdentity(); |
|
68 | } |
||
69 | } |
||
70 | 9 | return $this->identity; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Clear identity and user agent information |
||
75 | * |
||
76 | * @return void |
||
77 | */ |
||
78 | 2 | public function clearIdentity(): void |
|
83 | 2 | } |
|
84 | } |
||
85 |