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 ( 9e7309...ca86c4 )
by Aden
39:37 queued 06:18
created

AdminController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace LaravelFlare\Flare\Http\Controllers\Edge;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Contracts\Auth\Guard;
7
use LaravelFlare\Flare\Admin\AdminManager;
8
use Illuminate\Foundation\Bus\DispatchesJobs;
9
use Illuminate\Foundation\Auth\ResetsPasswords;
10
use LaravelFlare\Flare\Permissions\Permissions;
11
use Illuminate\Foundation\Auth\ThrottlesLogins;
12
use Illuminate\Foundation\Auth\AuthenticatesUsers;
13
use LaravelFlare\Flare\Http\Controllers\FlareController;
14
use LaravelFlare\Flare\Admin\Widgets\WidgetAdminManager;
15
16 View Code Duplication
class AdminController extends FlareController
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    use AuthenticatesUsers {
19
        AuthenticatesUsers::redirectPath insteadof ResetsPasswords;
20
        AuthenticatesUsers::getGuard insteadof ResetsPasswords;
21
    }
22
    use ResetsPasswords;
23
    use ThrottlesLogins;
24
    use DispatchesJobs;
25
26
    /**
27
     * Auth.
28
     * 
29
     * @var Guard
30
     */
31
    protected $auth;
32
33
    /**
34
     * __construct.
35
     * 
36
     * @param Guard        $auth
37
     * @param AdminManager $adminManager
38
     */
39
    public function __construct(Guard $auth, AdminManager $adminManager)
40
    {
41
        parent::__construct($adminManager);
42
43
        $this->auth = $auth;
44
    }
45
46
    /**
47
     * Show the Dashboard.
48
     * 
49
     * @return \Illuminate\Http\Response
50
     */
51
    public function getDashboard()
52
    {
53
        $view = 'admin.dashboard';
54
55
        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...
56
            $view = 'flare::'.$view;
57
        }
58
59
        return view($view, ['widgets' => (new WidgetAdminManager())]);
60
    }
61
62
    /**
63
     * Show the login form.
64
     *
65
     * @return \Illuminate\Http\Response
66
     */
67
    public function getLogin()
68
    {
69
        return view('flare::admin.login');
70
    }
71
72
    /**
73
     * Log the user.
74
     *
75
     * @return \Illuminate\Http\RedirectReponse
76
     */
77
    public function getLogout()
78
    {
79
        $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...
80
81
        return redirect('/');
82
    }
83
84
    /**
85
     * Display the form to request a password reset link.
86
     *
87
     * @return \Illuminate\Http\Response
88
     */
89
    public function getEmail()
90
    {
91
        return view('flare::admin.password');
92
    }
93
94
    /**
95
     * Display the form to request a password reset link.
96
     *
97
     * @return \Illuminate\Http\Response
98
     */
99
    public function getReset()
100
    {
101
        return view('flare::admin.reset');
102
    }
103
104
    /**
105
     * Performs the login redirect action.
106
     *
107
     * If the authenticated user has admin permissions
108
     * then they will be redirected into the admin
109
     * panel. If they do no, they will be sent
110
     * to the homepage of the website.
111
     * 
112
     * @return \Illuminate\Http\RedirectReponse
113
     */
114
    protected function loginRedirect()
115
    {
116
        if (Permissions::check()) {
117
            return redirect()->intended(\Flare::adminUrl());
118
        }
119
120
        return redirect('/');
121
    }
122
123
    /**
124
     * Method is called when the appropriate controller
125
     * method is unable to be found or called.
126
     * 
127
     * @param array $parameters
128
     * 
129
     * @return \Illuminate\Http\Response
130
     */
131
    public function missingMethod($parameters = array())
132
    {
133
        return view('flare::admin.404', []);
134
    }
135
}
136