Completed
Push — master ( e1cce4...d2c19b )
by David
09:34 queued 11s
created

UserRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 4 1
A rules() 0 6 1
A messages() 0 8 1
A failedValidation() 0 4 1
1
<?php
2
3
namespace Torralbodavid\DuckFunkCore\Http\Request\Avatar;
4
5
use Illuminate\Contracts\Validation\Validator;
6
use Illuminate\Foundation\Http\FormRequest;
7
use Torralbodavid\DuckFunkCore\Exceptions\Welcome\UserCheck;
8
use Torralbodavid\DuckFunkCore\Rules\UniqueUsername;
9
use Torralbodavid\DuckFunkCore\Rules\UsernameWithoutIllegalWords;
10
11
class UserRequest extends FormRequest
12
{
13
    /**
14
     * Determine if the user is authorized to make this request.
15
     *
16
     * @return bool
17
     */
18
    public function authorize()
19
    {
20
        return core()->user()->settings->can_change_name;
21
    }
22
23
    /**
24
     * Get the validation rules that apply to the request.
25
     * @return array
26
     */
27
    public function rules()
28
    {
29
        return [
30
            'name' => ['min:2', 'max:15', 'regex:/^[a-zA-Z0-9_\-=?!@:.,.-]*$/', new UsernameWithoutIllegalWords(), new UniqueUsername()],
31
        ];
32
    }
33
34
    /**
35
     * Get the error messages for the defined validation rules.
36
     *
37
     * @return array
38
     */
39
    public function messages()
40
    {
41
        return [
42
            'validation.regex' => 'No es válido',
43
            'validation.min.string' => 'Nombre corto',
44
            'validation.max.string' => 'Nombre largo',
45
        ];
46
    }
47
48
    protected function failedValidation(Validator $validator)
49
    {
50
        throw new UserCheck($validator);
51
    }
52
}
53