ChangePasswordRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 39
ccs 0
cts 16
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 3 1
A withValidator() 0 6 2
A rules() 0 6 1
1
<?php
2
3
namespace MedianetDev\LaravelAuthApi\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Hash;
8
9
class ChangePasswordRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @return bool
15
     */
16
    public function authorize()
17
    {
18
        return true;
19
    }
20
21
    /**
22
     * Get the validation rules that apply to the request.
23
     *
24
     * @return array
25
     */
26
    public function rules()
27
    {
28
        return [
29
            'old_password' => 'required',
30
            'new_password' => 'required|min:6|different:old_password',
31
            'confirm_password' => 'required|same:new_password|min:6',
32
        ];
33
    }
34
35
    /**
36
     * Configure the validator instance.
37
     *
38
     * @param \Illuminate\Validation\Validator $validator
39
     *
40
     * @return void
41
     */
42
    public function withValidator($validator)
43
    {
44
        $validator->after(function ($validator) {
45
            // check old password matches
46
            if (! Hash::check($this->input('old_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...
47
                $validator->errors()->add('old_password', 'old password incorrect.');
48
            }
49
        });
50
    }
51
}
52