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.
Completed
Push — master ( 6afaf0...b64b0a )
by Aden
03:06
created

AdminController   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 5
Bugs 4 Features 0
Metric Value
wmc 11
c 5
b 4
f 0
lcom 1
cbo 10
dl 0
loc 128
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getDashboard() 0 10 2
A getLogin() 0 4 1
A getLogout() 0 6 1
A getEmail() 0 4 1
A getReset() 0 4 1
A redirectPath() 0 8 2
A loginPath() 0 4 1
A missingMethod() 0 4 1
1
<?php
2
3
namespace LaravelFlare\Flare\Http\Controllers\LTS;
4
5
use Flare;
6
use Response;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Auth;
9
use Illuminate\Contracts\Auth\Guard;
10
use LaravelFlare\Flare\Admin\AdminManager;
11
use Illuminate\Foundation\Bus\DispatchesJobs;
12
use Illuminate\Foundation\Auth\RegistersUsers;
13
use LaravelFlare\Flare\Permissions\Permissions;
14
use Illuminate\Foundation\Auth\ThrottlesLogins;
15
use Illuminate\Foundation\Auth\ResetsPasswords;
16
use Illuminate\Foundation\Auth\AuthenticatesUsers;
17
use LaravelFlare\Flare\Http\Controllers\FlareController;
18
use LaravelFlare\Flare\Admin\Widgets\WidgetAdminManager;
19
20
class AdminController extends FlareController
21
{
22
    use AuthenticatesUsers;
23
    use ThrottlesLogins;
24
    use ResetsPasswords;
25
    use RegistersUsers;
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
    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
     * Log the user.
76
     *
77
     * @return \Illuminate\Http\RedirectReponse
78
     */
79
    public function getLogout()
80
    {
81
        $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...
82
83
        return redirect('/');
84
    }
85
86
    /**
87
     * Display the form to request a password reset link.
88
     *
89
     * @return \Illuminate\Http\Response
90
     */
91
    public function getEmail()
92
    {
93
        return view('flare::admin.password');
94
    }
95
96
    /**
97
     * Display the form to request a password reset link.
98
     *
99
     * @return \Illuminate\Http\Response
100
     */
101
    public function getReset()
102
    {
103
        return view('flare::admin.reset');
104
    }
105
106
    /**
107
     * Performs the login redirect action.
108
     *
109
     * If the authenticated user has admin permissions
110
     * then they will be redirected into the admin
111
     * panel. If they do no, they will be sent
112
     * to the homepage of the website.
113
     * 
114
     * @return \Illuminate\Http\RedirectReponse
115
     */
116
    public function redirectPath()
117
    {
118
        if (Permissions::check()) {
119
            return redirect()->intended(Flare::adminUrl());
120
        }
121
122
        return redirect('/');
123
    }
124
125
    /**
126
     * Get the path to the login route.
127
     *
128
     * @return string
129
     */
130
    public function loginPath()
131
    {
132
        return Flare::adminUrl('login');
133
    }
134
135
    /**
136
     * Method is called when the appropriate controller
137
     * method is unable to be found or called.
138
     * 
139
     * @param array $parameters
140
     * 
141
     * @return \Illuminate\Http\Response
142
     */
143
    public function missingMethod($parameters = array())
144
    {
145
        return Response::view('flare::admin.404', [], 404);
146
    }
147
}
148