Passed
Push — develop ( f8f4ab...7498d6 )
by Nikita
08:37
created

ProfileController::changePassword()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Gameap\Http\Controllers;
4
5
use Illuminate\Support\Facades\Auth;
6
use Gameap\Http\Requests\ProfileChangePasswordRequest;
7
use Hash;
8
9
class ProfileController extends AuthController
10
{
11
    /**
12
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
13
     */
14
    public function index()
15
    {
16
        return view('profile', [
17
            'user' => $user = Auth::user(),
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
18
        ]);
19
    }
20
21
    /**
22
     * @param ProfileChangePasswordRequest $request
23
     *
24
     * @return \Illuminate\Http\RedirectResponse
25
     */
26
    public function changePassword(ProfileChangePasswordRequest $request)
27
    {
28
        if (!(Hash::check($request->get('current_password'), Auth::user()->password))) {
0 ignored issues
show
Bug introduced by
Accessing password on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
29
            return redirect()->back()->with("error", "Your current password does not matches with the password you provided. Please try again.");
30
        }
31
32
        Auth::user()->update($request->only('password'));
33
        
34
        return redirect()->route('profile')
35
            ->with('success','Password changed successfully');
36
    }
37
}
38