Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StoreFeatureRequest
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 rules
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
1
 messages
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Requests\v2\Feature;
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 creating a new feature.
12 *
13 * @property string $key Unique identifier key (e.g., "character_limit", "bold")
14 * @property string $name Human-readable name (e.g., "Character Limit")
15 * @property string|null $description Description of the feature
16 * @property string $value_type Type of value: boolean, integer, string, array, object
17 * @property string $category Feature category: formatting, limits, storage, ai, general
18 * @property mixed $default_value Default value when not overridden by plan
19 * @property bool $is_active Whether the feature is active (default: true)
20 * @property int $display_order Order for display purposes (default: 0)
21 */
22class StoreFeatureRequest 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            'key' => [
35                'required',
36                'string',
37                'max:100',
38                'regex:/^[a-z][a-z0-9_]*$/',
39                Rule::unique('features', 'key'),
40            ],
41            'name' => 'required|string|max:255',
42            'description' => 'nullable|string|max:1000',
43            'value_type' => ['required', 'string', Rule::in(Feature::VALUE_TYPES)],
44            'category' => ['required', 'string', Rule::in(Feature::CATEGORIES)],
45            'default_value' => 'present',
46            'is_active' => 'sometimes|boolean',
47            'display_order' => 'sometimes|integer|min:0',
48        ];
49    }
50
51    /**
52     * Get custom messages for validator errors.
53     *
54     * @return array<string, string>
55     */
56    public function messages(): array
57    {
58        return [
59            'key.required' => 'The feature key is required.',
60            'key.regex' => 'The key must start with a letter and contain only lowercase letters, numbers, and underscores.',
61            'key.unique' => 'A feature with this key already exists.',
62            'name.required' => 'The feature name is required.',
63            'value_type.required' => 'The value type is required.',
64            'value_type.in' => 'The value type must be one of: '.implode(', ', Feature::VALUE_TYPES),
65            'category.required' => 'The category is required.',
66            'category.in' => 'The category must be one of: '.implode(', ', Feature::CATEGORIES),
67            'default_value.present' => 'The default value field must be present (can be null).',
68        ];
69    }
70}