Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| UpdateCustomerRequest | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| rules | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
12 | |||
| 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 UpdateCustomerRequest extends StoreCustomerRequest |
| 10 | { |
| 11 | /** |
| 12 | * Get the validation rules that apply to the request. |
| 13 | * |
| 14 | * @return array |
| 15 | */ |
| 16 | public function rules(): array |
| 17 | { |
| 18 | $fields = [ |
| 19 | 'firstname', 'lastname', 'email', 'password', |
| 20 | 'birth_date', 'address', 'phone', 'country', |
| 21 | 'city', 'postcode', 'opt_in' |
| 22 | ]; |
| 23 | $atLeast = function ($attribute) use ($fields) { |
| 24 | return 'required_without_all:' . collect($fields) |
| 25 | ->filter(function ($fieldName) use ($attribute) { |
| 26 | return $fieldName !== $attribute; |
| 27 | })->implode(','); |
| 28 | }; |
| 29 | return [ |
| 30 | 'firstname' => [$atLeast('firstname'), 'string', 'min:1', 'max:255'], |
| 31 | 'lastname' => [$atLeast('lastname'), 'string', 'min:1', 'max:255'], |
| 32 | 'email' => [$atLeast('email'), 'email:rfc,dns,spoof,filter', 'max:255'], |
| 33 | 'password' => [ |
| 34 | $atLeast('password'), 'max:255', Password::min(8) |
| 35 | ->mixedCase() |
| 36 | ->letters() |
| 37 | ->numbers() |
| 38 | ->symbols() |
| 39 | ->uncompromised() |
| 40 | ], |
| 41 | 'birth_date' => [$atLeast('birth_date'), 'date_format:Y-m-d', 'max:255'], |
| 42 | 'address' => [$atLeast('address'), 'required_with:address2', 'string', 'max:255'], |
| 43 | 'address2' => ['sometimes', 'string', 'max:255'], |
| 44 | 'phone' => [$atLeast('phone'), 'string', 'phone:' . ($this->currentCountry ? |
| 45 | $this->currentCountry->iso : implode(',', Country::getValidIsoAplha2Codes())), 'max:255'], |
| 46 | 'country' => [ |
| 47 | $atLeast('country'), |
| 48 | 'numeric', |
| 49 | new EnumIsValidRule(Country::class), |
| 50 | sprintf( |
| 51 | 'in:%s', |
| 52 | implode(',', Country::getValidCountries()) |
| 53 | ) |
| 54 | ], |
| 55 | 'city' => [$atLeast('city'), 'string', 'min:2', 'max:255'], |
| 56 | 'postcode' => [$atLeast('postcode'), 'string', 'postal_code:' . ($this->currentCountry ? |
| 57 | $this->currentCountry->iso : implode(',', Country::getValidIsoAplha2Codes())), 'max:255'], |
| 58 | 'opt_in' => [$atLeast('opt_in'), 'boolean'], |
| 59 | ]; |
| 60 | } |
| 61 | } |