Passed
Push — feature/application-fit-functi... ( 2528fc...b1d659 )
by Yonathan
04:31
created

StoreJobApplicationAnswer::authorize()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 4
nc 4
nop 0
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