GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AdminController::getLogout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace LaravelFlare\Flare\Http\Controllers\Edge;
4
5
use Flare;
6
use Response;
7
use Illuminate\Http\Request;
8
use Illuminate\Contracts\Auth\Guard;
9
use LaravelFlare\Flare\Admin\AdminManager;
10
use Illuminate\Foundation\Bus\DispatchesJobs;
11
use Illuminate\Foundation\Auth\ResetsPasswords;
12
use LaravelFlare\Flare\Permissions\Permissions;
13
use Illuminate\Foundation\Auth\ThrottlesLogins;
14
use Illuminate\Foundation\Auth\AuthenticatesUsers;
15
use LaravelFlare\Flare\Http\Controllers\FlareController;
16
use LaravelFlare\Flare\Admin\Widgets\WidgetAdminManager;
17
18
class AdminController extends FlareController
19
{
20
    use AuthenticatesUsers {
21
        AuthenticatesUsers::redirectPath insteadof ResetsPasswords;
22
        AuthenticatesUsers::credentials insteadof ResetsPasswords;
23
        AuthenticatesUsers::guard insteadof ResetsPasswords;
24
    }
25
    use ResetsPasswords;
26
    use DispatchesJobs;
27
28
    /**
29
     * Auth.
30
     * 
31
     * @var Guard
32
     */
33
    protected $auth;
34
35
    /**
36
     * __construct.
37
     * 
38
     * @param Guard        $auth
39
     * @param AdminManager $adminManager
40
     */
41
    public function __construct(Guard $auth, AdminManager $adminManager)
42
    {
43
        parent::__construct($adminManager);
44
45
        $this->auth = $auth;
46
    }
47
48
    /**
49
     * Show the Dashboard.
50
     * 
51
     * @return \Illuminate\Http\Response
52
     */
53 View Code Duplication
    public function getDashboard()
54
    {
55
        $view = 'admin.dashboard';
56
57
        if (!view()->exists($view)) {
0 ignored issues
show
Bug introduced by
The method exists does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\View\View.

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...
58
            $view = 'flare::'.$view;
59
        }
60
61
        return view($view, ['widgets' => (new WidgetAdminManager())]);
62
    }
63
64
    /**
65
     * Show the login form.
66
     *
67
     * @return \Illuminate\Http\Response
68
     */
69
    public function getLogin()
70
    {
71
        return view('flare::admin.login');
72
    }
73
74
    /**
75
     * Show the login form.
76
     *
77
     * @return \Illuminate\Http\Response
78
     */
79
    public function postLogin(Request $request)
80
    {
81
        return $this->login($request);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->login($request); of type Illuminate\Http\Redirect...lluminate\Http\Response adds the type Illuminate\Http\RedirectResponse to the return on line 81 which is incompatible with the return type documented by LaravelFlare\Flare\Http\...inController::postLogin of type Illuminate\Http\Response.
Loading history...
82
    }
83
84
    /**
85
     * Log the user.
86
     *
87
     * @return \Illuminate\Http\RedirectReponse
88
     */
89
    public function getLogout()
90
    {
91
        $this->auth->logout();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Illuminate\Contracts\Auth\Guard as the method logout() does only exist in the following implementations of said interface: Illuminate\Auth\SessionGuard.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
92
93
        return redirect('/');
94
    }
95
96
    /**
97
     * Display the form to request a password reset link.
98
     *
99
     * @return \Illuminate\Http\Response
100
     */
101
    public function getEmail()
102
    {
103
        return view('flare::admin.password');
104
    }
105
106
    /**
107
     * Display the form to request a password reset link.
108
     *
109
     * @return \Illuminate\Http\Response
110
     */
111
    public function getReset()
112
    {
113
        return view('flare::admin.reset');
114
    }
115
116
    /**
117
     * Performs the login redirect action.
118
     *
119
     * If the authenticated user has admin permissions
120
     * then they will be redirected into the admin
121
     * panel. If they do no, they will be sent
122
     * to the homepage of the website.
123
     * 
124
     * @return \Illuminate\Http\RedirectReponse
125
     */
126
    protected function loginRedirect()
127
    {
128
        dd('here');
129
        if (Permissions::check()) {
130
            return redirect()->intended(Flare::adminUrl());
131
        }
132
133
        return redirect('/');
134
    }
135
136
    /**
137
     * Method is called when the appropriate controller
138
     * method is unable to be found or called.
139
     * 
140
     * @param array $parameters
141
     * 
142
     * @return \Illuminate\Http\Response
143
     */
144
    public function missingMethod($parameters = array())
145
    {
146
        return Response::view('flare::admin.404', [], 404);
147
    }
148
}
149