Passed
Push — feature/job-builder/step-03-ui ( dabf2e...dabf2e )
by Xander
20:05 queued 13s
created

UpdateManager::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 51
ccs 31
cts 31
cp 1
rs 9.312
cc 1
nc 1
nop 0
crap 1

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
10
class UpdateManager extends FormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @return bool
1 ignored issue
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
16
     */
17 2
    public function authorize()
0 ignored issues
show
introduced by
Method \App\Http\Requests\UpdateManager::authorize() does not have return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
18
    {
19 2
        return true;
20
    }
21
22
    /**
23
     * Get the validation rules that apply to the request.
24
     *
25
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \App\Http\Requests\UpdateManager::rules() does not specify type hint for items of its traversable return value.
Loading history...
26
     */
27 2
    public function rules()
0 ignored issues
show
introduced by
Method \App\Http\Requests\UpdateManager::rules() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
28
    {
29 2
        $frequencyRule = new ValidIdRule(Frequency::class);
30
        return [
31 2
            'department_id' => ['nullable', new ValidIdRule(Department::class)],
32
            /*
33
             * Twitters Terms of Service only allows ". A username can only contain
34
             * alphanumeric characters (letters A-Z, numbers 0-9) with the exception
35
             * of underscores"
36
             * This regex will allow only alphamumeric characters and the underscore.
37
             * Keep this handy if we need to validate other usernames.
38
             */
39
            'twitter_username' => [
40
                'nullable', //Some people may not have a handle.
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// Some people may not have a handle." but found "//Some people may not have a handle."
Loading history...
41
                'max:15', //Per Twitter's Terms/Service.
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// Per Twitter's Terms/Service." but found "//Per Twitter's Terms/Service."
Loading history...
42
                'regex:/^[A-Za-z0-9_]+$/',
43
            ],
44
            'linkedin_url' => [
45
                'nullable', // Some people may not be on LinkedIn
46
                'regex:/^(https:\\/\\/|http:\\/\\/)?www\\.linkedin\\.com\\/in\\/[^\\/]+(\\/)?$/', // Validation for linkedIn profile URLS only.
47
            ],
48 2
            'work_review_frequency_id' => ['nullable', $frequencyRule],
49 2
            'stay_late_frequency_id' => ['nullable', $frequencyRule],
50 2
            'engage_team_frequency_id' => ['nullable', $frequencyRule],
51 2
            'development_opportunity_frequency_id' => ['nullable', $frequencyRule],
52 2
            'refuse_low_value_work_frequency_id' => ['nullable', $frequencyRule],
53 2
            'years_experience' => 'nullable|numeric',
54
55 2
            'en.about_me' => 'nullable|string',
56 2
            'en.greatest_accomplishment' => 'nullable|string',
57 2
            'en.branch' => 'nullable|string',
58 2
            'en.division' => 'nullable|string',
59 2
            'en.position' => 'nullable|string',
60 2
            'en.leadership_style' => 'nullable|string',
61 2
            'en.employee_learning' => 'nullable|string',
62 2
            'en.expectations' => 'nullable|string',
63 2
            'en.education' => 'nullable|string',
64 2
            'en.career_journey' => 'nullable|string',
65 2
            'en.learning_path' => 'nullable|string',
66
67 2
            'fr.about_me' => 'nullable|string',
68 2
            'fr.greatest_accomplishment' => 'nullable|string',
69 2
            'fr.branch' => 'nullable|string',
70 2
            'fr.division' => 'nullable|string',
71 2
            'fr.position' => 'nullable|string',
72 2
            'fr.leadership_style' => 'nullable|string',
73 2
            'fr.employee_learning' => 'nullable|string',
74 2
            'fr.expectations' => 'nullable|string',
75 2
            'fr.education' => 'nullable|string',
76 2
            'fr.career_journey' => 'nullable|string',
77 2
            'fr.learning_path' => 'nullable|string',
78
        ];
79
    }
80
}
81