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 ( 890028...40491b )
by Freek
13:56
created

WelcomeController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 44
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A showWelcomeForm() 0 7 1
A savePassword() 0 12 1
A sendPasswordSavedResponse() 0 4 1
A rules() 0 6 1
A redirectPath() 0 8 3
1
<?php
2
3
namespace Spatie\WelcomeNotification;
4
5
use Illuminate\Foundation\Auth\User;
6
use Illuminate\Http\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class WelcomeController
10
{
11
    public function showWelcomeForm(Request $request, User $user)
12
    {
13
        return view('welcomeNotification::welcome')->with([
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
14
            'email' => $request->email,
15
            'user' => $user,
16
        ]);
17
    }
18
19
    public function savePassword(Request $request, User $user)
20
    {
21
        $request->validate($this->rules());
0 ignored issues
show
Bug introduced by
The call to validate() misses a required argument $...$params.

This check looks for function calls that miss required arguments.

Loading history...
22
23
        $user->password = bcrypt($request->password);
24
        $user->welcome_valid_until = null;
25
        $user->save();
26
27
        auth()->login($user);
28
29
        return $this->sendPasswordSavedResponse();
30
    }
31
32
    protected function sendPasswordSavedResponse(): Response
33
    {
34
        return redirect()->to($this->redirectPath())->with('status', 'Welcome! You are now logged in!');
35
    }
36
37
    protected function rules()
38
    {
39
        return [
40
            'password' => 'required|confirmed|min:8',
41
        ];
42
    }
43
44
    public function redirectPath()
45
    {
46
        if (method_exists($this, 'redirectTo')) {
47
            return $this->redirectTo();
0 ignored issues
show
Bug introduced by
The method redirectTo() does not seem to exist on object<Spatie\WelcomeNot...tion\WelcomeController>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
        }
49
50
        return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
0 ignored issues
show
Bug introduced by
The property redirectTo does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
    }
52
}
53