AuthenticatedSessionController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A store() 0 13 1
A destroy() 0 10 1
1
<?php
2
3
namespace Devfaysal\LaravelAdmin\Http\Controllers\Auth;
4
5
use Carbon\Carbon;
6
use Devfaysal\LaravelAdmin\Http\Controllers\Controller;
7
use Devfaysal\LaravelAdmin\Http\Requests\Auth\LoginRequest;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Auth;
10
11
class AuthenticatedSessionController extends Controller
12
{
13
    /**
14
     * Display the login view.
15
     *
16
     * @return \Illuminate\View\View
17
     */
18
    public function create()
19
    {
20
        return view('laravel-admin::auth.login');
21
    }
22
23
    /**
24
     * Handle an incoming authentication request.
25
     *
26
     * @param  \App\Http\Requests\Auth\LoginRequest  $request
27
     * @return \Illuminate\Http\RedirectResponse
28
     */
29
    public function store(LoginRequest $request)
30
    {
31
        $request->authenticate();
32
33
        $request->session()->regenerate();
0 ignored issues
show
Bug introduced by
The method regenerate cannot be called on $request->session() (of type callable).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
34
35
        $admin = Auth::guard('admin')->user();
36
        $admin->last_login_at = Carbon::now()->toDateTimeString();
0 ignored issues
show
Bug introduced by
Accessing last_login_at on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
37
        $admin->last_login_ip = $request->getClientIp();
0 ignored issues
show
Bug introduced by
Accessing last_login_ip on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
38
        $admin->save();
39
40
        return redirect()->route('admins.dashboard');
41
    }
42
43
    /**
44
     * Destroy an authenticated session.
45
     *
46
     * @param  \Illuminate\Http\Request  $request
47
     * @return \Illuminate\Http\RedirectResponse
48
     */
49
    public function destroy(Request $request)
50
    {
51
        Auth::guard('admin')->logout();
0 ignored issues
show
Bug introduced by
The method logout does only exist in Illuminate\Contracts\Auth\StatefulGuard, but not in Illuminate\Contracts\Auth\Guard.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
52
53
        $request->session()->invalidate();
0 ignored issues
show
Bug introduced by
The method invalidate cannot be called on $request->session() (of type callable).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
54
55
        $request->session()->regenerateToken();
0 ignored issues
show
Bug introduced by
The method regenerateToken cannot be called on $request->session() (of type callable).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
56
57
        return redirect()->route('admins.login');
58
    }
59
}
60