Completed
Push — master ( 03b333...573f2e )
by Abdelrahman
02:45
created

processPersistenceFlush()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 17
rs 9.4285
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 Illuminate\Support\Facades\Lang;
20
use Rinvex\Fort\Contracts\UserRepositoryContract;
21
use Rinvex\Fort\Http\Controllers\AbstractController;
22
23
class ManagePersistenceController extends AbstractController
24
{
25
    /**
26
     * Create a new account controller instance.
27
     *
28
     * @param \Rinvex\Fort\Contracts\UserRepositoryContract $users
29
     *
30
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
31
     */
32
    public function __construct(UserRepositoryContract $users)
0 ignored issues
show
Unused Code introduced by
The parameter $users is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34
        $this->middleware($this->getAuthMiddleware(), ['except' => $this->middlewareWhitelist]);
35
    }
36
37
    /**
38
     * Show the account sessions.
39
     *
40
     * @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...
41
     */
42
    public function showPersistence()
43
    {
44
        return view('rinvex.fort::profile.persistence');
45
    }
46
47
    /**
48
     * Flush the given session.
49
     *
50
     * @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...
51
     *
52
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
53
     */
54
    public function processPersistenceFlush($token = null)
55
    {
56
        $status = '';
57
58
        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...
59
            app('rinvex.fort.persistence')->delete($token);
60
            $status = Lang::get('rinvex.fort::message.auth.session.flushed');
61
        } elseif (request()->get('confirm')) {
62
            app('rinvex.fort.persistence')->deleteByUser(Auth::guard($this->getGuard())->user()->id);
63
            $status = Lang::get('rinvex.fort::message.auth.session.flushedall');
64
        }
65
66
        return intend([
67
            'back' => true,
68
            'with' => ['rinvex.fort.alert.warning' => $status],
69
        ]);
70
    }
71
}
72