Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| GetBrandStatsRequest | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| rules | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests\Api\V2; |
| 4 | |
| 5 | use App\Http\Requests\Api\V2\BaseApiRequest; |
| 6 | use Illuminate\Support\Carbon; |
| 7 | use Illuminate\Validation\ValidationException; |
| 8 | |
| 9 | class GetBrandStatsRequest extends BaseApiRequest |
| 10 | { |
| 11 | /** |
| 12 | * Get the validation rules that apply to the request. |
| 13 | * |
| 14 | * @return array |
| 15 | * @throws ValidationException If given dates are unparsable of period is bigger than 3 months. |
| 16 | * @throws \Exception If carbon date processing failed. |
| 17 | */ |
| 18 | public function rules(): array |
| 19 | { |
| 20 | try { |
| 21 | if (Carbon::parse($this->end)->diffInMonths(Carbon::parse($this->start)->addDay()) >= 3) { |
| 22 | throw ValidationException::withMessages([ |
| 23 | 'Vous devez sélectionner une période de maximum 3 mois' |
| 24 | ]); |
| 25 | } |
| 26 | } catch (\Exception $e) { |
| 27 | if (\get_class($e) !== ValidationException::class) { |
| 28 | throw ValidationException::withMessages([ |
| 29 | 'Les dates séléectionnées ne sembles pas être valides' |
| 30 | ]); |
| 31 | } |
| 32 | throw $e; |
| 33 | } |
| 34 | return [ |
| 35 | 'start' => 'required|date|date_format:Y-m-d', |
| 36 | 'end' => 'required|date|date_format:Y-m-d|after_or_equal:start', |
| 37 | ]; |
| 38 | } |
| 39 | } |