Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| UpsertCallTypeSettingsRequest | |
100.00% |
16 / 16 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| authorize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| rules | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| callType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isSupportedCallType | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests\v2\RolePlay; |
| 4 | |
| 5 | use App\Http\Models\RolePlayCallTypeSettings; |
| 6 | use App\Http\Services\RolePlay\RolePlayCallTypeSettingsService; |
| 7 | use Illuminate\Foundation\Http\FormRequest; |
| 8 | |
| 9 | /** |
| 10 | * Request for upserting a RolePlay call-type target duration at any scope. |
| 11 | * |
| 12 | * The `allow_user_override` field is only honored by the company-scope |
| 13 | * controller and is ignored at system and user scope. |
| 14 | * |
| 15 | * @property int $target_duration_seconds Target duration for the call type |
| 16 | * (between 30 and 3600 seconds) |
| 17 | * @property bool|null $allow_user_override Company scope only — when false, |
| 18 | * users cannot override this target |
| 19 | * with their own per-user row. |
| 20 | */ |
| 21 | class UpsertCallTypeSettingsRequest extends FormRequest |
| 22 | { |
| 23 | public function authorize(): bool |
| 24 | { |
| 25 | return true; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> |
| 30 | */ |
| 31 | public function rules(): array |
| 32 | { |
| 33 | return [ |
| 34 | 'target_duration_seconds' => [ |
| 35 | 'required', |
| 36 | 'integer', |
| 37 | 'min:'.RolePlayCallTypeSettingsService::MIN_TARGET_SECONDS, |
| 38 | 'max:'.RolePlayCallTypeSettingsService::MAX_TARGET_SECONDS, |
| 39 | ], |
| 40 | 'allow_user_override' => 'sometimes|boolean', |
| 41 | ]; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Raw call_type route parameter. Callers should validate the value via |
| 46 | * {@see isSupportedCallType()} before acting on it so a 422 response can |
| 47 | * be returned from the controller instead of a 500 exception trail. |
| 48 | */ |
| 49 | public function callType(): string |
| 50 | { |
| 51 | return (string) $this->route('callType'); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * True when the {callType} URL segment is one of the values the resolver |
| 56 | * knows how to handle. |
| 57 | */ |
| 58 | public function isSupportedCallType(): bool |
| 59 | { |
| 60 | return in_array( |
| 61 | $this->callType(), |
| 62 | RolePlayCallTypeSettings::SUPPORTED_CALL_TYPES, |
| 63 | true, |
| 64 | ); |
| 65 | } |
| 66 | } |