Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
StoreAdministratorRequest
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 authorize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 rules
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
 failedValidation
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Requests;
4
5use App\Rules\SpanishPostalCode;
6use Illuminate\Contracts\Validation\Validator;
7use Illuminate\Foundation\Http\FormRequest;
8use Illuminate\Http\Exceptions\HttpResponseException;
9
10class StoreAdministratorRequest extends FormRequest
11{
12    public function authorize(): bool
13    {
14        return true;
15    }
16
17    public function rules(): array
18    {
19        return [
20            'name'                   => 'required|string|max:255',
21            'address'                => 'nullable|string|max:255',
22            'postal_code'            => ['nullable', 'string', new SpanishPostalCode],
23            'city'                   => 'nullable|string|max:255',
24            'province'               => 'nullable|string|max:255',
25            'email'                  => 'nullable|email|max:255',
26            'phone'                  => 'nullable|string|max:50',
27            'assigned_commercial_id' => 'nullable|integer',
28        ];
29    }
30
31    protected function failedValidation(Validator $validator): never
32    {
33        throw new HttpResponseException(
34            response(['message' => 'KO', 'errors' => $validator->errors()], 422)
35        );
36    }
37}