Completed
Push — master ( cdb114...273f6a )
by Abdelrahman
02:18
created

UserSessionsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 4 1
A flush() 0 17 3
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Http\Controllers\Frontend;
17
18
use Illuminate\Support\Facades\Auth;
19
use Rinvex\Fort\Http\Controllers\AuthorizedController;
20
21
class UserSessionsController extends AuthorizedController
22
{
23
    /**
24
     * Show the account sessions.
25
     *
26
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
27
     */
28
    public function index()
29
    {
30
        return view('rinvex.fort::frontend.user.sessions');
31
    }
32
33
    /**
34
     * Flush the given session.
35
     *
36
     * @param string $token
0 ignored issues
show
Documentation introduced by
Should the type for parameter $token not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
37
     *
38
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
39
     */
40
    public function flush($token = null)
41
    {
42
        $status = '';
43
44
        if ($token) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $token of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
45
            app('rinvex.fort.persistence')->delete($token);
46
            $status = trans('rinvex.fort::frontend/messages.auth.session.flushed');
47
        } elseif (request()->get('confirm')) {
48
            app('rinvex.fort.persistence')->deleteByUser(Auth::guard($this->getGuard())->user()->id);
49
            $status = trans('rinvex.fort::frontend/messages.auth.session.flushedall');
50
        }
51
52
        return intend([
53
            'back' => true,
54
            'with' => ['rinvex.fort.alert.warning' => $status],
55
        ]);
56
    }
57
}
58