Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
EditCompanyRequest
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 authorize
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 rules
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3namespace App\Http\Requests;
4
5use Illuminate\Foundation\Http\FormRequest;
6use Illuminate\Validation\Rule;
7
8class EditCompanyRequest extends FormRequest
9{
10    /**
11     * Determine if the user is authorized to make this request.
12     */
13    public function authorize(): bool
14    {
15        return true;
16    }
17
18    /**
19     * Get the validation rules that apply to the request.
20     *
21     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
22     */
23    public function rules(): array
24    {
25        $request = $this;
26
27        return [
28            'company.company_name' => ['required', 'string', 'max:255', Rule::unique('companies', 'name')->ignore($request->company['id'], '_id')],
29            'company.company_address_line1' => 'required|string',
30            'company.company_address_line2' => 'nullable|string',
31            'company.city' => 'nullable|string|max:255',
32            'company.state' => 'nullable|string|max:255',
33            'company.country' => 'required|string|max:255',
34            'company.zip_code' => 'nullable|string|max:20',
35            'company.term_of_contract' => 'required|integer|min:0',
36            'company.custom_term_of_contract' => 'required_if:term_of_contract,0|nullable|integer|min:1',
37            'company.contract_start_date' => 'required|date_format:m/d/y',
38            'company.contract_end_date' => [
39                'required',
40                'regex:/^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/(\d{2}|\d{4})$/',
41                'after_or_equal:contract_start_date'
42            ],
43            'company.business_pro_enterprise_plus' => ['required', 'array', 'min:1', function ($attribute, $value, $fail) {
44                if (in_array('no', $value) && (in_array('yes_dedicated', $value) || in_array('yes_community', $value))) {
45                    $fail('You cannot select "No" along with any "Yes" options.');
46                }
47            }],
48            'company.business_pro_enterprise_plus.*' => 'required|string|in:no,yes_dedicated,yes_community',
49            'company.total_licenses' => [
50                'required',
51                'integer',
52                'min:0',
53                function ($attribute, $value, $fail) use ($request) {
54                    $sum = $request->input('company.starter', 0)
55                        + $request->input('company.growth', 0)
56                        + $request->input('company.sales_pro', 0)
57                        + $request->input('company.sales_pro_teams_smb', 0);
58                    if ($value != $sum) {
59                        $fail('The total licenses must equal the sum of starter, growth, sales_pro, and sales_pro_teams_smb licenses.');
60                    }
61                }
62            ],
63            'company.starter' => 'integer|min:0',
64            'company.growth' => 'integer|min:0',
65            'company.sales_pro' => 'integer|min:0',
66            'company.sales_pro_teams_smb' => 'integer|min:0',
67            'company.auto_renewal' => 'boolean',
68            'company.extend_contract_end_date' => ['required', 'numeric', 'in:0,1,3,5,7'],
69        ];
70    }
71}