Completed
Push — develop ( 554465...735a56 )
by Abdelrahman
02:03
created

RegistrationProcessRequest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 8 2
A process() 0 7 1
A withValidator() 0 11 3
A rules() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Fort\Http\Requests\Frontend;
6
7
use Cortex\Fort\Models\User;
8
use Rinvex\Support\Http\Requests\FormRequest;
9
use Cortex\Foundation\Exceptions\GenericException;
10
11
class RegistrationProcessRequest extends FormRequest
12
{
13
    /**
14
     * Determine if the user is authorized to make this request.
15
     *
16
     * @throws \Cortex\Foundation\Exceptions\GenericException
17
     *
18
     * @return bool
19
     */
20
    public function authorize()
21
    {
22
        if (! config('rinvex.fort.registration.enabled')) {
23
            throw new GenericException(trans('cortex/fort::messages.register.disabled'));
24
        }
25
26
        return true;
27
    }
28
29
    /**
30
     * Process given request data before validation.
31
     *
32
     * @param array $data
33
     *
34
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,boolean|array>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
35
     */
36
    public function process($data)
37
    {
38
        $data['active'] = ! config('rinvex.fort.registration.moderated');
39
        $data['roles'] = [config('rinvex.fort.registration.default_role')];
40
41
        return $data;
42
    }
43
44
    /**
45
     * Configure the validator instance.
46
     *
47
     * @param \Illuminate\Validation\Validator $validator
48
     *
49
     * @return void
50
     */
51
    public function withValidator($validator)
52
    {
53
        $validator->after(function ($validator) {
54
            $data = $this->all();
55
            $password = $data['password'] ?? null;
56
57
            if ($password && $password !== $data['password_confirmation']) {
58
                $validator->errors()->add('password', trans('validation.confirmed', ['attribute' => 'password']));
59
            }
60
        });
61
    }
62
63
    /**
64
     * Get the validation rules that apply to the request.
65
     *
66
     * @return array
67
     */
68
    public function rules()
69
    {
70
        return (new User())->getRules();
71
    }
72
}
73