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