Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
81.48% covered (warning)
81.48%
22 / 27
83.33% covered (warning)
83.33%
5 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
PlanComparisonExportRequest
81.48% covered (warning)
81.48%
22 / 27
83.33% covered (warning)
83.33%
5 / 6
10.64
0.00% covered (danger)
0.00%
0 / 1
 rules
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 prepareForValidation
54.55% covered (warning)
54.55%
6 / 11
0.00% covered (danger)
0.00%
0 / 1
7.35
 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
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 exporting plan comparison data as CSV (admin).
12 *
13 * This request validates query parameters for the plan comparison export endpoint
14 * which returns a downloadable CSV file comparing features across plans.
15 *
16 * @property array<string>|null $plan_ids Specific plan IDs to compare (exports 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 column (default: false)
20 */
21class PlanComparisonExportRequest extends FormRequest
22{
23    use AuthorizesVengresoAdmin;
24
25    /**
26     * Get the validation rules that apply to the request.
27     *
28     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
29     */
30    public function rules(): array
31    {
32        return [
33            'plan_ids' => 'sometimes|array|min:1',
34            'plan_ids.*' => 'string|max:24',
35            'category' => [
36                'sometimes',
37                'nullable',
38                'string',
39                Rule::in(Feature::CATEGORIES),
40            ],
41            'active_only' => 'sometimes|boolean',
42            'include_hubspot' => 'sometimes|boolean',
43        ];
44    }
45
46    /**
47     * Prepare the data for validation.
48     *
49     * Converts string booleans to actual booleans and handles comma-separated plan_ids.
50     */
51    protected function prepareForValidation(): void
52    {
53        // Handle comma-separated plan_ids as string
54        if ($this->has('plan_ids') && is_string($this->input('plan_ids'))) {
55            $planIds = array_filter(explode(',', $this->input('plan_ids')));
56            $this->merge(['plan_ids' => $planIds]);
57        }
58
59        // Convert string booleans
60        if ($this->has('active_only')) {
61            $this->merge([
62                'active_only' => filter_var($this->input('active_only'), FILTER_VALIDATE_BOOLEAN),
63            ]);
64        }
65
66        if ($this->has('include_hubspot')) {
67            $this->merge([
68                'include_hubspot' => filter_var($this->input('include_hubspot'), FILTER_VALIDATE_BOOLEAN),
69            ]);
70        }
71    }
72
73    /**
74     * Get the validated plan IDs or null if not provided.
75     *
76     * @return array<string>|null
77     */
78    public function getPlanIds(): ?array
79    {
80        return $this->validated('plan_ids');
81    }
82
83    /**
84     * Get the category filter or null if not provided.
85     */
86    public function getCategory(): ?string
87    {
88        return $this->validated('category');
89    }
90
91    /**
92     * Check if only active plans should be included.
93     */
94    public function isActiveOnly(): bool
95    {
96        return $this->input('active_only', true);
97    }
98
99    /**
100     * Check if HubSpot status should be included.
101     */
102    public function shouldIncludeHubspot(): bool
103    {
104        return $this->input('include_hubspot', false);
105    }
106}