Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
UpdateRolePlayProjectRequest
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 authorize
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 prepareForValidation
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 rules
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\RolePlay;
4
5use App\Http\Models\RolePlayProjects;
6use App\Http\Services\RolePlay\ObjectionNormalizer;
7use Illuminate\Foundation\Http\FormRequest;
8
9class UpdateRolePlayProjectRequest extends FormRequest
10{
11    /**
12     * Determine if the user is authorized to make this request.
13     */
14    public function authorize(): bool
15    {
16        $user = $this->user();
17
18        $project = $this->route('persona');
19
20        return ! $project || $user->id === $project->user_id;
21    }
22
23    /**
24     * Normalize any legacy-shape `objections` payload (string options or
25     * duplicate categories) into the canonical {text, company_sizes}
26     * shape BEFORE validation rules fire. Keeps older clients working.
27     */
28    protected function prepareForValidation(): void
29    {
30        if ($this->has('objections')) {
31            $this->merge([
32                'objections' => ObjectionNormalizer::normalize($this->input('objections')),
33            ]);
34        }
35    }
36
37    /**
38     * Get the validation rules that apply to the request.
39     */
40    public function rules(): array
41    {
42        return RolePlayProjects::getRules();
43    }
44}