Completed
Push — master ( 61a212...d68c52 )
by Sebastian
04:09
created

PasswordController::resetPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace App\Http\Controllers\Back;
4
5
use App\Http\Controllers\Controller;
6
use App\Services\Auth\Back\User;
7
use Illuminate\Foundation\Auth\ResetsPasswords;
8
use Illuminate\Http\Request;
9
10 View Code Duplication
class PasswordController extends Controller
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...
11
{
12
    use ResetsPasswords {
13
        ResetsPasswords::reset as defaultReset;
14
    }
15
16
    /** @var string */
17
    protected $guard;
18
19
    /** @var string */
20
    protected $broker;
21
22
    /** @var string */
23
    protected $linkRequestView;
24
25
    /** @var string */
26
    protected $resetView;
27
28
    /** @var string */
29
    protected $subject;
30
31
    public function __construct()
32
    {
33
        $this->guard = 'back';
34
        $this->broker = 'back';
35
        $this->linkRequestView = 'back.auth.password';
36
        $this->resetView = 'back.auth.reset';
37
        $this->subject = fragment('passwords.subjectEmail').' '.config('app.url');
38
    }
39
40
    public function redirectPath()
41
    {
42
        return action('Back\AuthController@getLogin');
43
    }
44
45
    public function showResetForm(Request $request, $token = null)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47
        if (empty($token)) {
48
            return redirect()->action('Back\PasswordController@getEmail');
49
        }
50
51
        $user = User::findByToken($token);
52
53
        if (empty($user)) {
54
            return redirect()->action('Back\PasswordController@getEmail');
55
        }
56
57
        return view($this->resetView)->with(compact('user', 'token'));
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...
58
    }
59
60
    public function reset(Request $request)
61
    {
62
        // We use min. 8 character passwords, so doing some extra validation here.
63
        $this->validate($request, [
64
            'password' => 'required|confirmed|min:8',
65
        ]);
66
67
        return $this->defaultReset($request);
68
    }
69
70
    protected function resetPassword($user, $password)
71
    {
72
        $user->password = $password;
73
74
        $user->save();
75
76
        auth()->guard($this->getGuard())->login($user);
77
    }
78
}
79