SessionAuthGateway   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 8 2
A log() 0 4 1
A wikiSessionId() 0 3 1
1
<?php
2
3
4
namespace App\Src\UseCases\Infra\Gateway;
5
6
7
use App\Src\UseCases\Domain\Shared\Gateway\AuthGateway;
8
use App\Src\UseCases\Domain\User;
9
use Illuminate\Support\Facades\Auth;
10
use Illuminate\Support\Facades\Session;
11
12
class SessionAuthGateway implements AuthGateway
13
{
14
    public function current(): ?User
15
    {
16
        $userModel = Auth::user();
17
        if(!isset($userModel)){
18
            return null;
19
        }
20
        $roles = $userModel->roles()->pluck('name')->toArray();
21
        return new User($userModel->uuid, $userModel->email, $userModel->firstname, $userModel->lastname, $userModel->organization_id, $userModel->path_picture, $roles, $userModel->providers);
22
    }
23
24
    public function log(User $u)
25
    {
26
        $authenticate = \App\User::where('uuid', $u->id())->first();
27
        Auth::login($authenticate, true);
28
    }
29
30
    public function wikiSessionId():? string
31
    {
32
        return Session::get('wiki_session_id');
33
    }
34
35
}
36