Passed
Push — 5.0.0 ( f10804...44b42e )
by Fèvre
15:04 queued 07:40
created

UserValidator::updateEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Models\Validators;
6
7
use Illuminate\Support\Facades\Validator as FacadeValidator;
8
use Illuminate\Validation\Rule;
9
use Illuminate\Validation\Validator;
10
11
class UserValidator
12
{
13
    /**
14
     * Get the validator for an incoming registration request with a social provider.
15
     *
16
     * @param array $data The data to validate.
17
     *
18
     * @return Validator
19
     */
20
    public static function createWithProvider(array $data): Validator
21
    {
22
        $rules = [
23
            'username' => 'required|alpha_num|min:4|max:20|unique:users',
24
            'email' => 'required|email|max:50|unique:users'
25
        ];
26
27
        return FacadeValidator::make($data, $rules);
28
    }
29
30
    /**
31
     * Get a validator for an incoming update request. (Administration)
32
     *
33
     * @param array $data The data to validate.
34
     * @param int $id The actual user id to ignore the username rule.
35
     *
36
     * @return Validator
37
     */
38
    public static function update(array $data, int $id): Validator
39
    {
40
        $rules = [
41
            'username' => [
42
                'required',
43
                'alpha_num',
44
                'min:4',
45
                'max:20',
46
                Rule::unique('users')->ignore($id)
47
            ],
48
            'email' => [
49
                'required',
50
                'email',
51
                'max:50',
52
                Rule::unique('users')->ignore($id)
53
            ],
54
            'account.first_name' => 'max:100',
55
            'account.last_name' => 'max:100',
56
            'account.facebook' => 'max:50',
57
            'account.twitter' => 'max:50',
58
            'roles' => 'required'
59
        ];
60
61
        return FacadeValidator::make($data, $rules);
62
    }
63
}
64