Passed
Push — activity-logs ( 999e93...08c980 )
by Fèvre
08:30
created

SecurityController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A index() 0 20 2
1
<?php
2
namespace Xetaravel\Http\Controllers;
3
4
use Illuminate\Http\Request;
5
use Illuminate\Support\Facades\Auth;
6
use Illuminate\View\View;
7
use Propa\BrowscapPHP\Facades\Browscap;
8
use Xetaravel\Models\Session;
9
10
class SecurityController extends Controller
11
{
12
    /**
13
     * Constructor
14
     */
15
    public function __construct()
16
    {
17
        parent::__construct();
18
19
        $this->breadcrumbs->addCrumb('Security', route('users.security.index'));
20
    }
21
22
    /**
23
     * Show the security index page.
24
     *
25
     * @return \Illuminate\View\View
26
     */
27
    public function index(Request $request): View
28
    {
29
        $records = Session::expires()->where('user_id', Auth::id())->get();
30
31
        $sessions = [];
32
33
        foreach ($records as $record) {
34
            $infos = Browscap::getBrowser($record->user_agent);
0 ignored issues
show
Bug Best Practice introduced by
The property user_agent does not exist on Xetaravel\Models\Session. Since you implemented __get, consider adding a @property annotation.
Loading history...
35
36
            $record->infos = $infos;
0 ignored issues
show
Bug Best Practice introduced by
The property infos does not exist on Xetaravel\Models\Session. Since you implemented __set, consider adding a @property annotation.
Loading history...
37
38
            array_push($sessions, $record);
39
        }
40
41
        $sessionId = $request->session()->getId();
42
43
        return view('security.index', [
44
            'sessions' => $sessions,
45
            'sessionId' => $sessionId,
46
            'breadcrumbs' => $this->breadcrumbs
47
        ]);
48
    }
49
}
50