Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
46 / 46 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| StoreClientRequest | |
100.00% |
46 / 46 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| authorize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| rules | |
100.00% |
42 / 42 |
|
100.00% |
1 / 1 |
1 | |||
| failedValidation | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests; |
| 4 | |
| 5 | use App\Rules\SpanishPostalCode; |
| 6 | use Illuminate\Contracts\Validation\Validator; |
| 7 | use Illuminate\Foundation\Http\FormRequest; |
| 8 | use Illuminate\Http\Exceptions\HttpResponseException; |
| 9 | |
| 10 | class StoreClientRequest extends FormRequest |
| 11 | { |
| 12 | public function authorize(): bool |
| 13 | { |
| 14 | return true; |
| 15 | } |
| 16 | |
| 17 | public function rules(): array |
| 18 | { |
| 19 | return [ |
| 20 | 'company_name' => 'required|string|max:255', |
| 21 | 'client_type_id' => 'nullable|integer|exists:tbl_client_types,id', |
| 22 | 'fiscal_id' => 'nullable|string|max:255', |
| 23 | 'address' => 'nullable|string|max:255', |
| 24 | 'postal_code' => ['nullable', 'string', new SpanishPostalCode], |
| 25 | 'city' => 'nullable|string|max:255', |
| 26 | 'province' => 'nullable|string|max:255', |
| 27 | 'segment_id' => 'nullable|integer|exists:tbl_segments,segment_id', |
| 28 | 'strategy_type_id' => 'nullable|integer|exists:tbl_strategy_types,id', |
| 29 | 'administrator_id' => 'nullable|integer|exists:tbl_administrators,id', |
| 30 | 'scope' => 'nullable|string', |
| 31 | 'region' => 'nullable|string', |
| 32 | 'annual_maintenance' => 'nullable|boolean', |
| 33 | 'annual_maint_start_date' => 'nullable|date', |
| 34 | 'annual_maint_frequency' => 'nullable|string', |
| 35 | 'quarterly_maintenance' => 'nullable|boolean', |
| 36 | 'quarterly_maint_start_date' => 'nullable|date', |
| 37 | 'quarterly_maint_frequency' => 'nullable|string', |
| 38 | 'contract_end_date' => 'nullable|date', |
| 39 | 'last_work_date' => 'nullable|date', |
| 40 | 'fire_suppression' => 'nullable|boolean', |
| 41 | 'fire_detection' => 'nullable|boolean', |
| 42 | 'water' => 'nullable|boolean', |
| 43 | 'relationship_status' => 'nullable|string', |
| 44 | 'termination_date' => 'nullable|date', |
| 45 | 'non_client_contract_end_date'=> 'nullable|date', |
| 46 | 'payment_method' => 'nullable|string', |
| 47 | 'client_annual_billing' => 'nullable|numeric|min:0', |
| 48 | 'fire_current_billing' => 'nullable|numeric|min:0', |
| 49 | 'fire_billing_potential' => 'nullable|numeric|min:0', |
| 50 | 'contact_name' => 'nullable|string|max:255', |
| 51 | 'contact_phone' => 'nullable|string|max:50', |
| 52 | 'contact_email' => 'nullable|email|max:255', |
| 53 | 'notes' => 'nullable|string', |
| 54 | 'gestiona_client_code' => 'nullable|integer', |
| 55 | 'associated_billing_client' => 'nullable|string|max:255', |
| 56 | 'allows_communications' => 'nullable|boolean', |
| 57 | 'last_visit_date' => 'nullable|date', |
| 58 | 'commercial_ids' => 'nullable|array', |
| 59 | 'commercial_ids.*' => 'integer|exists:users,id', |
| 60 | ]; |
| 61 | } |
| 62 | |
| 63 | protected function failedValidation(Validator $validator): never |
| 64 | { |
| 65 | throw new HttpResponseException( |
| 66 | response(['message' => 'KO', 'errors' => $validator->errors()], 422) |
| 67 | ); |
| 68 | } |
| 69 | } |