Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
52 / 52
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StoreGlobalSettingsRequest
100.00% covered (success)
100.00%
52 / 52
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 rules
100.00% covered (success)
100.00%
45 / 45
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\GlobalSettings;
4
5use App\Http\Requests\v2\Parameter\Concerns\AuthorizesVengresoAdmin;
6use Illuminate\Foundation\Http\FormRequest;
7
8/**
9 * Request for creating/resetting global settings to defaults.
10 *
11 * All fields are optional - if not provided, defaults will be used.
12 *
13 * @property float|null $wage_per_hour Average hourly wage for calculations (min: 0)
14 * @property int|null $words_per_minute Typing speed in words per minute (min: 1)
15 * @property string|null $typing_style The typing style setting
16 * @property int|null $typing_speed The typing speed value (min: 1)
17 * @property bool|null $remove_grammar_on_lose_focus Whether to remove grammar on focus loss
18 * @property string|null $fly_rewrite FlyRewrite feature status ('enabled'/'disabled')
19 * @property string|null $fly_grammar FlyGrammar feature status ('enabled'/'disabled')
20 * @property string|null $fly_grammar_default_language Default language for FlyGrammar
21 * @property array{flyCuts?: bool, flyGrammar?: bool, gmailPlugin?: bool, linkedinPlugin?: bool, flyPosts?: bool, flyEngage?: bool, outlookPlugin?: bool, developerMode?: bool}|null $features Feature flags
22 * @property array<string, array{title: string, link: string, description: string}>|null $playlists Playlist configurations
23 * @property array<string>|null $ignoredInputTypes Input types to ignore
24 * @property array<string>|null $blackListClasses CSS classes to blacklist
25 * @property array<string>|null $blackListIds Element IDs to blacklist
26 * @property array<array{name: string, value: string}>|null $blackListAttributes Attribute name/value pairs to blacklist
27 * @property array<array{domain: string, blackListClasses: array, blackListIds: array, blackListAttributes: array}>|null $blackListDomainRules Domain-specific blacklist rules
28 */
29class StoreGlobalSettingsRequest extends FormRequest
30{
31    use AuthorizesVengresoAdmin;
32
33    /**
34     * Get the validation rules that apply to the request.
35     *
36     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
37     */
38    public function rules(): array
39    {
40        return [
41            // Core settings
42            'wage_per_hour' => 'sometimes|numeric|min:0',
43            'words_per_minute' => 'sometimes|integer|min:1',
44            'typing_style' => 'sometimes|string|max:50',
45            'typing_speed' => 'sometimes|integer|min:1',
46            'remove_grammar_on_lose_focus' => 'sometimes|boolean',
47
48            // Feature toggles
49            'fly_rewrite' => 'sometimes|string|in:enabled,disabled',
50            'fly_grammar' => 'sometimes|string|in:enabled,disabled',
51            'fly_grammar_default_language' => 'sometimes|string|max:10',
52
53            // Feature flags
54            'features' => 'sometimes|array',
55            'features.flyCuts' => 'sometimes|boolean',
56            'features.flyGrammar' => 'sometimes|boolean',
57            'features.gmailPlugin' => 'sometimes|boolean',
58            'features.linkedinPlugin' => 'sometimes|boolean',
59            'features.flyPosts' => 'sometimes|boolean',
60            'features.flyEngage' => 'sometimes|boolean',
61            'features.outlookPlugin' => 'sometimes|boolean',
62            'features.developerMode' => 'sometimes|boolean',
63
64            // Playlists
65            'playlists' => 'sometimes|array',
66            'playlists.*' => 'array',
67            'playlists.*.title' => 'required_with:playlists.*|string|max:255',
68            'playlists.*.link' => 'required_with:playlists.*|string|url|max:500',
69            'playlists.*.description' => 'required_with:playlists.*|string|max:1000',
70
71            // Blacklists
72            'ignoredInputTypes' => 'sometimes|array',
73            'ignoredInputTypes.*' => 'string|max:50',
74
75            'blackListClasses' => 'sometimes|array',
76            'blackListClasses.*' => 'string|max:100',
77
78            'blackListIds' => 'sometimes|array',
79            'blackListIds.*' => 'string|max:100',
80
81            'blackListAttributes' => 'sometimes|array',
82            'blackListAttributes.*' => 'array',
83            'blackListAttributes.*.name' => 'required_with:blackListAttributes.*|string|max:100',
84            'blackListAttributes.*.value' => 'required_with:blackListAttributes.*|string|max:255',
85
86            'blackListDomainRules' => 'sometimes|array',
87            'blackListDomainRules.*' => 'array',
88            'blackListDomainRules.*.domain' => 'required_with:blackListDomainRules.*|string|max:255',
89            'blackListDomainRules.*.blackListClasses' => 'sometimes|array',
90            'blackListDomainRules.*.blackListClasses.*' => 'string|max:100',
91            'blackListDomainRules.*.blackListIds' => 'sometimes|array',
92            'blackListDomainRules.*.blackListIds.*' => 'string|max:100',
93            'blackListDomainRules.*.blackListAttributes' => 'sometimes|array',
94            'blackListDomainRules.*.blackListAttributes.*' => 'array',
95            'blackListDomainRules.*.blackListAttributes.*.name' => 'required|string|max:100',
96            'blackListDomainRules.*.blackListAttributes.*.value' => 'required|string|max:255',
97        ];
98    }
99
100    /**
101     * Get custom messages for validator errors.
102     *
103     * @return array<string, string>
104     */
105    public function messages(): array
106    {
107        return [
108            'wage_per_hour.min' => 'The wage per hour must be a positive number.',
109            'words_per_minute.min' => 'The words per minute must be at least 1.',
110            'fly_rewrite.in' => 'The fly rewrite status must be either enabled or disabled.',
111            'fly_grammar.in' => 'The fly grammar status must be either enabled or disabled.',
112            'playlists.*.link.url' => 'Each playlist must have a valid URL.',
113        ];
114    }
115}