Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
10 / 12
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
IndexPlanRequest
83.33% covered (warning)
83.33%
10 / 12
50.00% covered (danger)
50.00%
1 / 2
5.12
0.00% covered (danger)
0.00%
0 / 1
 prepareForValidation
66.67% covered (warning)
66.67%
4 / 6
0.00% covered (danger)
0.00%
0 / 1
4.59
 rules
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Requests\v2\Plan\Admin;
4
5use App\Http\Requests\v2\Parameter\Concerns\AuthorizesVengresoAdmin;
6use Illuminate\Foundation\Http\FormRequest;
7
8/**
9 * Request for listing plans (admin).
10 *
11 * @property string|null $filter Optional search filter for plan titles/identifiers
12 * @property int|null $per_page Number of items per page (default: 15)
13 * @property int|null $page Page number
14 * @property bool|null $include_subscription_counts Whether to include active subscription counts per plan (default: false)
15 */
16class IndexPlanRequest extends FormRequest
17{
18    use AuthorizesVengresoAdmin;
19
20    /**
21     * Prepare the data for validation.
22     *
23     * Converts string "true"/"false" to actual boolean values for query parameters.
24     */
25    protected function prepareForValidation(): void
26    {
27        if ($this->has('include_subscription_counts')) {
28            $value = $this->input('include_subscription_counts');
29
30            // Convert string "true"/"false" to boolean
31            if ($value === 'true') {
32                $this->merge(['include_subscription_counts' => true]);
33            } elseif ($value === 'false') {
34                $this->merge(['include_subscription_counts' => false]);
35            }
36        }
37    }
38
39    /**
40     * Get the validation rules that apply to the request.
41     *
42     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
43     */
44    public function rules(): array
45    {
46        return [
47            'filter' => 'sometimes|nullable|string|max:255',
48            'per_page' => 'sometimes|integer|min:1|max:100',
49            'page' => 'sometimes|integer|min:1',
50            'include_subscription_counts' => 'sometimes|boolean',
51        ];
52    }
53}