Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.97% covered (success)
96.97%
32 / 33
85.71% covered (warning)
85.71%
6 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
PlanComparisonRequest
96.97% covered (success)
96.97%
32 / 33
85.71% covered (warning)
85.71%
6 / 7
11
0.00% covered (danger)
0.00%
0 / 1
 rules
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
1
 prepareForValidation
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
5
 getPlanIds
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCategory
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isActiveOnly
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 shouldIncludeHubspot
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getResponseFormat
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Http\Requests\v2\Plan\Admin;
4
5use App\Http\Models\Feature;
6use App\Http\Requests\v2\Parameter\Concerns\AuthorizesVengresoAdmin;
7use Illuminate\Foundation\Http\FormRequest;
8use Illuminate\Validation\Rule;
9
10/**
11 * Request for getting plan comparison data (admin).
12 *
13 * This request validates query parameters for the plan comparison endpoint
14 * which returns a matrix comparing features across multiple plans.
15 *
16 * @property array<string>|null $plan_ids Specific plan IDs to compare (compares all active plans if omitted)
17 * @property string|null $category Filter features by category (formatting, limits, storage, ai, general)
18 * @property bool $active_only Only include active plans (default: true)
19 * @property bool $include_hubspot Include HubSpot configuration status (default: true)
20 * @property string $format Response format: "matrix" for comparison grid or "detailed" for full data (default: matrix)
21 */
22class PlanComparisonRequest extends FormRequest
23{
24    use AuthorizesVengresoAdmin;
25
26    /**
27     * Get the validation rules that apply to the request.
28     *
29     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
30     */
31    public function rules(): array
32    {
33        return [
34            'plan_ids' => 'sometimes|array|min:1',
35            'plan_ids.*' => 'string|max:24',
36            'category' => [
37                'sometimes',
38                'nullable',
39                'string',
40                Rule::in(Feature::CATEGORIES),
41            ],
42            'active_only' => 'sometimes|boolean',
43            'include_hubspot' => 'sometimes|boolean',
44            'format' => [
45                'sometimes',
46                'string',
47                Rule::in(['matrix', 'detailed']),
48            ],
49        ];
50    }
51
52    /**
53     * Prepare the data for validation.
54     *
55     * Converts string booleans to actual booleans and handles comma-separated plan_ids.
56     */
57    protected function prepareForValidation(): void
58    {
59        // Handle comma-separated plan_ids as string
60        if ($this->has('plan_ids') && is_string($this->input('plan_ids'))) {
61            $planIds = array_filter(explode(',', $this->input('plan_ids')));
62            $this->merge(['plan_ids' => $planIds]);
63        }
64
65        // Convert string booleans
66        if ($this->has('active_only')) {
67            $this->merge([
68                'active_only' => filter_var($this->input('active_only'), FILTER_VALIDATE_BOOLEAN),
69            ]);
70        }
71
72        if ($this->has('include_hubspot')) {
73            $this->merge([
74                'include_hubspot' => filter_var($this->input('include_hubspot'), FILTER_VALIDATE_BOOLEAN),
75            ]);
76        }
77    }
78
79    /**
80     * Get the validated plan IDs or null if not provided.
81     *
82     * @return array<string>|null
83     */
84    public function getPlanIds(): ?array
85    {
86        return $this->validated('plan_ids');
87    }
88
89    /**
90     * Get the category filter or null if not provided.
91     */
92    public function getCategory(): ?string
93    {
94        return $this->validated('category');
95    }
96
97    /**
98     * Check if only active plans should be included.
99     */
100    public function isActiveOnly(): bool
101    {
102        return $this->input('active_only', true);
103    }
104
105    /**
106     * Check if HubSpot status should be included.
107     */
108    public function shouldIncludeHubspot(): bool
109    {
110        return $this->input('include_hubspot', true);
111    }
112
113    /**
114     * Get the response format (matrix or detailed).
115     */
116    public function getResponseFormat(): string
117    {
118        return $this->input('format', 'matrix');
119    }
120}