Completed
Push — bug/accordion ( 6550f4...474aef )
by Grant
12:54 queued 07:32
created

UpdateApplicationProfileValidator::__construct()   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 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Services\Validation\Requests;
4
5
use App\Services\Validation\BaseDataValidator;
6
use App\Services\Validation\Contracts\DataValidator;
7
use App\Models\Applicant;
8
use Illuminate\Validation\Rule;
9
use Illuminate\Support\Facades\Validator;
10
use App\Services\Validation\Rules\PasswordCorrectRule;
11
use App\Services\Validation\Rules\PasswordFormatRule;
12
13
class UpdateApplicationProfileValidator extends BaseDataValidator implements DataValidator
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class UpdateApplicationProfileValidator
Loading history...
14
{
15
    /**
16
     * The Applicant this application is indented to belong to
17
     *
18
     * @var Applicant
19
     */
20
    protected $applicant;
21
22
    /**
23
     * Construct a validator for Update Application Profile form.
24
     *
25
     * @param Applicant $applicant The applicant this profile is intended to belong to.
26
     */
27 18
    public function __construct(Applicant $applicant)
28
    {
29 18
        $this->applicant = $applicant;
30 18
    }
31
32
    /**
33
     * Get the validation rules that apply to the request.
34
     *
35
     * @return mixed[]
36
     */
37 18
    public function rules() : array
38
    {
39
        return [
40
            // Name validation
41 18
            'profile_name' => 'required|string|max:191',
42
43
            // Email validation
44
            'profile_email' => [
45 18
                'required',
46 18
                'string',
47 18
                'max:191',
48 18
                'email',
49
                // Email may match existing email for this user,
50
                //  but must be unique if changed.
51 18
                Rule::unique('users', 'email')->ignore($this->applicant->user->id)
52
            ],
53
54
            //Password validation
55
            'old_password' => [
56 18
                'nullable',
57 18
                'required_with:new_password',
58 18
                new PasswordCorrectRule
59
            ],
60
            'new_password' => [
61 18
                'nullable',
62 18
                'min:8',
63 18
                new PasswordFormatRule,
64 18
                'confirmed'
65
            ],
66
67
            //Social Media Validation
68
            /*
69
             * Twitters Terms of Service only allows ". A username can only contain
70
             * alphanumeric characters (letters A-Z, numbers 0-9) with the exception
71
             * of underscores"
72
             * This regex will allow only alphamumeric characters and the underscore.
73
             * Keep this handy if we need to validate other usernames.
74
             */
75
            'twitter_username' => [
76
                'nullable', //Some people may not have a handle.
77
                'max:15', //Per Twitter's Terms/Service.
78
                'regex:/^[A-Za-z0-9_]+$/',
79
            ],
80
            'linkedin_url' => [
81
                'nullable', // Some people may not be on LinkedIn
82
                'regex:/^(https:\\/\\/|http:\\/\\/)?www\\.linkedin\\.com\\/in\\/[^\\/]+(\\/)?$/', // Validation for linkedIn profile URLS only.
83
            ],
84
85
            //Other Information Tagline
86
            'tagline' => [
87
                'nullable',
88
                'string'
89
            ],
90
        ];
91
    }
92
93
    /**
94
     * Returns a validator made with this data
95
     *
96
     * @param  mixed[] $data Data to validate.
97
     * @return Validator
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
98
     */
99 18
    public function validator(array $data) : \Illuminate\Validation\Validator
100
    {
101 18
        return Validator::make($data, $this->rules());
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...($data, $this->rules()) returns the type Illuminate\Contracts\Validation\Validator which includes types incompatible with the type-hinted return Illuminate\Validation\Validator.
Loading history...
102
    }
103
}
104