Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
40 / 40 |
| StoreCustomerRequest | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
40 / 40 |
| rules | |
100.00% |
1 / 1 |
1 | |
100.00% |
38 / 38 |
|||
| messages | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests\Api\V2; |
| 4 | |
| 5 | use App\Enums\Country; |
| 6 | use Illuminate\Validation\Rules\Password; |
| 7 | use Kwaadpepper\Enum\Rules\EnumIsValidRule; |
| 8 | |
| 9 | class StoreCustomerRequest extends BaseApiRequest |
| 10 | { |
| 11 | /** |
| 12 | * Get the validation rules that apply to the request. |
| 13 | * |
| 14 | * @return array |
| 15 | */ |
| 16 | public function rules(): array |
| 17 | { |
| 18 | return [ |
| 19 | 'firstname' => 'required|string|min:1|max:255', |
| 20 | 'lastname' => 'required|string|min:1|max:255', |
| 21 | 'email' => 'required|email:rfc,dns,spoof,filter|max:255', |
| 22 | 'password' => [ |
| 23 | 'required', |
| 24 | 'max:255', |
| 25 | Password::min(8) |
| 26 | ->mixedCase() |
| 27 | ->letters() |
| 28 | ->numbers() |
| 29 | ->symbols() |
| 30 | ->uncompromised() |
| 31 | ], |
| 32 | 'birth_date' => 'required|date_format:Y-m-d|max:255', |
| 33 | 'address' => 'sometimes|required_with:address2|string|max:255', |
| 34 | 'address2' => 'sometimes|string|max:255', |
| 35 | 'phone' => 'sometimes|string|phone:FR,BE,LU', |
| 36 | 'country' => [ |
| 37 | 'sometimes', |
| 38 | 'numeric', |
| 39 | new EnumIsValidRule(Country::class), |
| 40 | sprintf( |
| 41 | 'in:%s', |
| 42 | implode(',', [ |
| 43 | Country::belgium()->value, |
| 44 | Country::luxembourg()->value, |
| 45 | Country::france()->value, |
| 46 | // * DROM COM. |
| 47 | Country::guadeloupe()->value, |
| 48 | Country::martinique()->value, |
| 49 | Country::frenchGuiana()->value, |
| 50 | Country::reunion()->value, |
| 51 | Country::saintPierreAndMiquelon()->value, |
| 52 | Country::mayotte()->value, |
| 53 | Country::saintBarthelemy()->value, |
| 54 | Country::saintMartinFrenchPart()->value, |
| 55 | Country::wallisAndFutuna()->value, |
| 56 | Country::frenchPolynesia()->value, |
| 57 | Country::newCaledonia()->value |
| 58 | ]) |
| 59 | ) |
| 60 | ], |
| 61 | 'city' => 'sometimes|string|min:2|max:255', |
| 62 | 'postcode' => 'sometimes|string|postal_code:FR,BE,LU', |
| 63 | 'opt_in' => 'required|boolean', |
| 64 | ]; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Messages |
| 69 | * |
| 70 | * @return array |
| 71 | */ |
| 72 | public function messages() |
| 73 | { |
| 74 | return [ |
| 75 | // phpcs:ignore Generic.Files.LineLength.TooLong |
| 76 | 'phone.phone' => trans('Le champ :attribute est invalide, il accepte les numéros des pays suivants France, Belgique, Luxembourg.'), |
| 77 | // phpcs:ignore Generic.Files.LineLength.TooLong |
| 78 | 'country.in' => trans('Le champ :attribute est invalide, il accepte les pays suivants France, Belgique, Luxembourg.') |
| 79 | ]; |
| 80 | } |
| 81 | } |