Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
13.33% covered (danger)
13.33%
2 / 15
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReportingFormRequest
13.33% covered (danger)
13.33%
2 / 15
50.00% covered (danger)
50.00%
1 / 2
8.86
0.00% covered (danger)
0.00%
0 / 1
 authorize
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 rules
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Http\Requests;
4
5use App\Http\Models\Auth\Role;
6use Illuminate\Foundation\Http\FormRequest;
7
8class ReportingFormRequest extends FormRequest
9{
10    /**
11     * Determine if the user is authorized to make this request.
12     * Restricts access to Vengreso Admin users only.
13     */
14    public function authorize(): bool
15    {
16        $user = $this->user();
17
18        return $user && $user->hasRole(Role::VENGRESO_ADMIN);
19    }
20
21    /**
22     * Get the validation rules that apply to the request.
23     *
24     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
25     */
26    public function rules(): array
27    {
28        return [
29            'month_period' => 'required_without_all:from_date,to_date|in:1,3,6,12',
30            'from_date' => 'sometimes|date',
31            'to_date' => 'required_with:fromDate|date',
32            'companies' => 'sometimes|nullable|array',
33            'companies.*' => 'string|exists:companies,_id',
34            'groups' => 'sometimes|nullable|array',
35            'groups.*' => 'string|exists:company_groups,_id',
36            'subgroups' => 'sometimes|nullable|array',
37            'subgroups.*' => 'string|exists:company_groups,_id',
38            'users' => 'sometimes|nullable|array',
39            'users.*' => 'string|exists:users,_id',
40        ];
41    }
42}