ChangePasswordController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace MedianetDev\LaravelAuthApi\Http\Controllers;
4
5
use Illuminate\Support\Facades\Auth;
6
use Illuminate\Support\Facades\Hash;
7
use MedianetDev\LaravelAuthApi\Http\Helpers\ApiResponse;
8
use MedianetDev\LaravelAuthApi\Http\Requests\ChangePasswordRequest;
9
10
class ChangePasswordController extends Controller
11
{
12
    /**
13
     * Create a new controller instance.
14
     *
15
     * @return void
16
     */
17
    public function __construct()
18
    {
19
        $this->middleware('auth:api');
20
    }
21
22
    public function changePassword(ChangePasswordRequest $request)
23
    {
24
        $user = Auth::guard('apiauth')->user();
25
        $user->password = Hash::make($request->new_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...
26
        $user->save();
27
28
        return ApiResponse::send(['status' => 'Password changed successfully'], 1, 200, 'Password changed successfully');
29
    }
30
}
31