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

BatchUpdateApplicationReview   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 10 1
A authorize() 0 16 4
1
<?php
2
3
namespace App\Http\Requests;
4
5
use App\Models\ApplicationReview;
6
use Illuminate\Foundation\Http\FormRequest;
7
8
class BatchUpdateApplicationReview 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 === null) {
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
        $applicationReviews = ApplicationReview::whereIn('id', $inputIds)->get();
24
25
        foreach ($applicationReviews as $applicationReview) {
26
            if (!$user->can('update', $applicationReview)) {
27
                return false;
28
            }
29
        }
30
        return true;
31
    }
32
33
34
    /**
35
     * Get the validation rules that apply to the request.
36
     *
37
     * @return array
38
     */
39
    public function rules()
40
    {
41
        return [
42
            '*.id' => 'required|exists:application_reviews,id',
43
            '*.job_application_id' => 'required|exists:job_applications,id',
44
            '*.review_status_id' => 'nullable|exists:review_statuses,id',
45
            '*.notes' => 'nullable|string',
46
            '*.department_id' => 'nullable|exists:departments,id',
47
            '*.director_email_sent' => 'boolean',
48
            '*.reference_email_sent' => 'boolean',
49
        ];
50
    }
51
}
52