Passed
Push — task/refactor-application-data... ( 30e714...e7ce5c )
by Tristan
04:51
created

StoreJobApplicationAnswer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 6 1
A authorize() 0 10 4
1
<?php
2
3
namespace App\Http\Requests;
4
5
use App\Models\JobApplication;
6
use App\Models\JobApplicationAnswer;
7
use App\Models\JobPosterQuestion;
8
use App\Services\Validation\Rules\ValidIdRule;
9
use Illuminate\Foundation\Http\FormRequest;
10
11
class StoreJobApplicationAnswer extends FormRequest
12
{
13
    /**
14
     * Determine if the user is authorized to make this request.
15
     *
16
     * @return bool
17
     */
18
    public function authorize()
19
    {
20
        $job_application_id = $this->input('job_application_id');
21
        $application = JobApplication::find($job_application_id);
22
        $user = $this->user();
23
24
        return $application !== null
25
            && $user !== null
26
            && $user->can('create', JobApplicationAnswer::class)
27
            && $user->can('update', $application);
28
    }
29
30
    /**
31
     * Get the validation rules that apply to the request.
32
     *
33
     * @return array
34
     */
35
    public function rules()
36
    {
37
        return [
38
            'job_poster_question_id' => ['required', 'numeric', new ValidIdRule(JobPosterQuestion::class)],
39
            'job_application_id' => ['required', 'numeric', new ValidIdRule(JobApplication::class)],
40
            'answer' => 'nullable|string',
41
        ];
42
    }
43
}
44