Passed
Push — master ( 60125b...8a61d1 )
by Koen
02:54
created

UpdateRequest::authorize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Http\Requests\Api\Profile\Password;
6
7
use Illuminate\Contracts\Hashing\Hasher;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
final class UpdateRequest extends FormRequest
11
{
12
    public function rules(): array
13
    {
14
        return [
15
            'password'         => [
16
                'required',
17 3
                'string',
18
                'min:10',
19 3
                'max:191',
20
                'confirmed',
21
            ],
22
            'current_password' => [
23
                'required',
24
                'string',
25
                function ($attribute, $value, $fail) {
26
                    /** @var \App\Models\User $user */
27 3
                    $user = $this->user();
28
29
                    /** @var Hasher $hasher */
30
                    $hasher = $this->container->make(Hasher::class);
31 3
32
                    if (! $hasher->check($value, $user->getAuthPassword())) {
33
                        $fail('Current password is invalid.');
34
                    }
35
                },
36
            ],
37
        ];
38 3
    }
39
}
40