ChangePinRequest::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 18
rs 9.9332
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Ikechukwukalu\Requirepin\Requests;
4
5
use Ikechukwukalu\Requirepin\Rules\CurrentPin;
6
use Ikechukwukalu\Requirepin\Rules\DisallowOldPin;
7
use Illuminate\Foundation\Http\FormRequest;
8
use Illuminate\Validation\Rules\Password;
9
10
class ChangePinRequest extends FormRequest
11
{
12
13
    public function authorize(): bool
14
    {
15
        return true;
16
    }
17
18
    public function rules(): array
19
    {
20
        return [
21
            /**
22
             * You must allow default pin for RULE `CurrentPin`
23
             * so that the pin can be changed from the default value.
24
             * In order to do that we set it to receive a boolean
25
             * value TRUE as a first parameter
26
             */
27
            'current_pin' => ['required', 'string', new CurrentPin(true)],
28
            'pin' => [
29
                        'required', 'string',
30
                        'max:' . config('requirepin.max', 4),
31
                        Password::min(config('requirepin.min', 4))->numbers(),
32
                        'confirmed',
33
                        new DisallowOldPin(
34
                            config('requirepin.check_all', true),
35
                            config('requirepin.number', 4)
36
                        )
37
                    ],
38
        ];
39
    }
40
}
41