Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
AssignFeaturesRequest
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 rules
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 messages
100.00% covered (success)
100.00%
7 / 7
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 assigning features to a plan (admin).
10 *
11 * @property array<array{feature_id: string, value: mixed, is_enabled?: bool}> $features Array of feature assignments
12 */
13class AssignFeaturesRequest extends FormRequest
14{
15    use AuthorizesVengresoAdmin;
16
17    /**
18     * Get the validation rules that apply to the request.
19     *
20     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
21     */
22    public function rules(): array
23    {
24        return [
25            'features' => 'required|array',
26            'features.*.feature_id' => 'required|string|exists:features,_id',
27            'features.*.value' => 'present',
28            'features.*.is_enabled' => 'sometimes|boolean',
29        ];
30    }
31
32    /**
33     * Get custom messages for validator errors.
34     *
35     * @return array<string, string>
36     */
37    public function messages(): array
38    {
39        return [
40            'features.required' => 'The features array is required.',
41            'features.array' => 'The features must be an array.',
42            'features.*.feature_id.required' => 'Each feature must have a feature_id.',
43            'features.*.feature_id.exists' => 'The feature_id must reference an existing feature.',
44            'features.*.value.present' => 'Each feature must have a value field (can be null).',
45        ];
46    }
47}