Passed
Push — feature/word_counter ( c4ec23...76dc11 )
by Yonathan
16:47
created

UpdateJobPoster   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 53
dl 0
loc 71
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 5 2
A rules() 0 52 1
1
<?php
2
3
namespace App\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
use Illuminate\Support\Facades\Config;
7
use App\Services\Validation\Rules\ValidIdRule;
8
use App\Models\Lookup\Department;
9
use App\Models\Lookup\Province;
10
use App\Models\Lookup\SecurityClearance;
11
use App\Models\Lookup\LanguageRequirement;
12
use App\Models\JobPoster;
13
use App\Models\Lookup\Frequency;
14
15
class UpdateJobPoster extends FormRequest
16
{
17
    /**
18
     * Determine if the user is authorized to make this request.
19
     *
20
     * @return boolean
21
     */
22
    public function authorize(): bool
23
    {
24
        $job = $this->route('job');
25
        // Published jobs cannot be updated.
26
        return $job && $job->published_at === null;
27
    }
28
29
    /**
30
     * Get the validation rules that apply to the request.
31
     *
32
     * @return string[]
33
     */
34
    public function rules(): array
35
    {
36
        $dateFormat = Config::get('app.api_datetime_format');
37
        $dateFormatRule = "date_format:$dateFormat";
38
        $sliderRule = 'between:1,4';
39
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('term_qty' ...' => 'nullable|string') returns an array which contains values of type array<integer,App\Servic...>|array<integer,string> which are incompatible with the documented value type string.
Loading history...
40
            'term_qty' => 'nullable|numeric',
41
            'open_date_time' =>['nullable', $dateFormatRule],
42
            'close_date_time' => ['nullable', $dateFormatRule],
43
            'start_date_time' =>['nullable', $dateFormatRule],
44
            'department_id' => ['nullable', new ValidIdRule(Department::class)],
45
            'province_id' => ['nullable', new ValidIdRule(Province::class)],
46
            'security_clearance_id' => ['nullable', new ValidIdRule(SecurityClearance::class)],
47
            'language_requirement_id' => ['nullable', new ValidIdRule(LanguageRequirement::class)],
48
            'salary_min' => 'nullable|numeric',
49
            'salary_max' => 'nullable|numeric',
50
            'noc' => 'nullable|numeric',
51
            'classification_code' => 'nullable|regex:/[A-Z]{2}/',
52
            'classification_level' => 'nullable|numeric',
53
            'remote_work_allowed' => 'nullable|boolean',
54
            'team_size' => 'nullable|numeric',
55
            'work_env_features' => 'nullable|array',
56
            'work_env_features.*' => 'boolean', // Ensure work_env_features is an array of boolean flags.
57
            'fast_vs_steady' => ['nullable', $sliderRule],
58
            'horizontal_vs_vertical' => ['nullable', $sliderRule],
59
            'experimental_vs_ongoing' => ['nullable', $sliderRule],
60
            'citizen_facing_vs_back_office' => ['nullable', $sliderRule],
61
            'collaborative_vs_independent' => ['nullable', $sliderRule],
62
            'telework_allowed_frequency_id' => ['nullable', new ValidIdRule(Frequency::class)],
63
            'flexible_hours_frequency_id' => ['nullable', new ValidIdRule(Frequency::class)],
64
            'en.city' => 'nullable|string',
65
            'en.title' => 'nullable|string',
66
            'en.dept_impact' => 'nullable|string',
67
            'en.team_impact' => 'nullable|string',
68
            'en.hire_impact' => 'nullable|string',
69
            'en.division' => 'nullable|string',
70
            'en.branch' => 'nullable|string',
71
            'en.education' => 'nullable|string',
72
            'en.work_env_description' => 'nullable|string',
73
            'en.culture_summary' => 'nullable|string',
74
            'en.culture_special' => 'nullable|string',
75
            'fr.city' => 'nullable|string',
76
            'fr.title' => 'nullable|string',
77
            'fr.dept_impact' => 'nullable|string',
78
            'fr.team_impact' => 'nullable|string',
79
            'fr.hire_impact' => 'nullable|string',
80
            'fr.division' => 'nullable|string',
81
            'fr.branch' => 'nullable|string',
82
            'fr.education' => 'nullable|string',
83
            'fr.work_env_description' => 'nullable|string',
84
            'fr.culture_summary' => 'nullable|string',
85
            'fr.culture_special' => 'nullable|string',
86
        ];
87
    }
88
}
89