Passed
Push — task/applicant-skill-save-api ( 2ebd5d...fa7a9c )
by
unknown
06:31 queued 10s
created

BatchUpdateExperienceSkill::authorize()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 19
rs 9.2222
cc 6
nc 4
nop 0
1
<?php
2
3
namespace App\Http\Requests;
4
5
use App\Models\ExperienceSkill;
6
use Illuminate\Foundation\Http\FormRequest;
7
8
class BatchUpdateExperienceSkill extends FormRequest
9
{
10
    /**
11
     * Determine if the user is authorized to make this request.
12
     *
13
     * @return bool
14
     */
15
    public function authorize()
16
    {
17
        $user = $this->user();
18
        if (!$user->can('create', ExperienceSkill::class)) {
19
            return false;
20
        }
21
22
        $inputIds = collect($this->all())->pluck('id')->all();
0 ignored issues
show
Bug introduced by
The function collect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        $inputIds = /** @scrutinizer ignore-call */ collect($this->all())->pluck('id')->all();
Loading history...
23
        $experienceSkills = ExperienceSkill::with('experience')->whereIn('id', $inputIds)->get();
24
        foreach ($experienceSkills as $experienceSkill) {
25
            if ($experienceSkill->experience === null ||
26
                $user === null ||
27
                !$user->can('update', $experienceSkill->experience)
28
            ) {
29
                return false;
30
            }
31
        }
32
33
        return true;
34
    }
35
36
    /**
37
     * Get the validation rules that apply to the request.
38
     *
39
     * @return array
40
     */
41
    public function rules()
42
    {
43
        return [
44
          '*.id' => 'required|exists:App\Models\ExperienceSkill,id',
45
          '*.justification' => 'nullable|string',
46
        ];
47
    }
48
}
49