Passed
Push — dev ( 69b6f1...3c5138 )
by Chris
12:29 queued 05:29
created

UpdateManagerProfileRequest::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 64
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 50
c 2
b 0
f 0
dl 0
loc 64
rs 9.0909
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
use App\Services\Validation\Rules\ValidIdRule;
7
use App\Models\Lookup\Frequency;
8
use App\Models\Lookup\Department;
9
use App\Services\Validation\Rules\LinkedInUrlRule;
10
use Illuminate\Validation\Rule;
11
use App\Services\Validation\Rules\PasswordCorrectRule;
12
use App\Services\Validation\Rules\PasswordFormatRule;
13
use App\Services\Validation\Rules\TwitterHandleRule;
14
15
class UpdateManagerProfileRequest extends FormRequest
16
{
17
    /**
18
     * Validator instance updated on failedValidation.
19
     *
20
     * @var \Illuminate\Contracts\Validation\Validator
21
     */
22
    public $validator = null;
23
24
    /**
25
     * Determine if the user is authorized to make this request.
26
     *
27
     * @return boolean
28
     */
29
    public function authorize()
30
    {
31
        return $this->manager !== null;
32
    }
33
34
    /**
1 ignored issue
show
Coding Style Documentation introduced by
Doc comment for parameter "$validator" missing
Loading history...
35
     * Override Handle a failed validation attempt.
36
     *
37
     * @return void
38
     */
39
    protected function failedValidation(\Illuminate\Contracts\Validation\Validator $validator)
40
    {
41
        $this->validator = $validator;
42
    }
43
44
    /**
45
     * Get the validation rules that apply to the request.
46
     *
47
     * @return array
48
     */
49
    public function rules()
50
    {
51
        $frequencyRule = new ValidIdRule(Frequency::class);
52
        return [
53
            'name' => 'required|string|max:191',
54
            'email' => [
55
                'required',
56
                'string',
57
                'max:191',
58
                'email',
59
                // Email may match existing email for this user,
60
                // but must be unique if changed.
61
                Rule::unique('users', 'email')->ignore($this->manager->user->id)
62
            ],
63
            'gov_email' => [
64
                'nullable',
65
                'string',
66
                'max:191',
67
                'email',
68
            ],
69
            // Password validation
70
            'current_password' => [
71
                'nullable',
72
                'required_with:new_password',
73
                new PasswordCorrectRule
74
            ],
75
            'new_password' => [
76
                'nullable',
77
                'min:8',
78
                new PasswordFormatRule,
79
                'confirmed'
80
            ],
81
82
            'department_id' => ['required', new ValidIdRule(Department::class)],
83
            'telework_allowed_frequency_id' => ['required', $frequencyRule],
84
            'flexible_hours_frequency_id' => ['required', $frequencyRule],
85
86
            'team_size' => 'nullable|numeric|min:1',
87
            'years_experience' => 'nullable|numeric|min:0',
88
            'gc_directory_url' => 'nullable|url',
89
90
            '*.about_me' => 'nullable|string',
91
            '*.career_journey' => 'nullable|string',
92
            '*.branch' => 'nullable|string',
93
            '*.division' => 'nullable|string',
94
            '*.education' => 'nullable|string',
95
            '*.employee_learning' => 'nullable|string',
96
            '*.expectations' => 'nullable|string',
97
            '*.greatest_accomplishment' => 'nullable|string',
98
            '*.how_we_work' => 'nullable|string',
99
            '*.leadership_style' => 'nullable|string',
100
            '*.learning_path' => 'nullable|string',
101
            '*.operating_context' => 'nullable|string',
102
            '*.position' => 'nullable|string',
103
            '*.things_to_know' => 'nullable|string',
104
            '*.what_we_value' => 'nullable|string',
105
106
            'twitter_username' => [
107
                'nullable', // Some people may not have a handle.
108
                new TwitterHandleRule,
109
            ],
110
            'linkedin_url' => [
111
                'nullable', // Some people may not be on LinkedIn.
112
                new LinkedInUrlRule,
113
            ],
114
        ];
115
    }
116
}
117