Passed
Push — feature/job-builder/step-03-ui ( dabf2e...dabf2e )
by Xander
20:05 queued 13s
created

StoreRatingGuideAnswer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 2
b 0
f 0
dl 0
loc 31
ccs 0
cts 11
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 6 1
A authorize() 0 11 4
1
<?php
2
3
namespace App\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
use App\Models\RatingGuideAnswer;
7
use App\Models\RatingGuideQuestion;
8
use App\Services\Validation\Rules\ValidIdRule;
9
use App\Models\Criteria;
10
11
class StoreRatingGuideAnswer extends FormRequest
12
{
13
    /**
14
     * Determine if the user is authorized to make this request.
15
     *
16
     * @return bool
1 ignored issue
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
17
     */
18
    public function authorize()
0 ignored issues
show
introduced by
Method \App\Http\Requests\StoreRatingGuideAnswer::authorize() does not have return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
19
    {
20
        // Ensure the user can make answers, and is the owner of the question it answers.
21
        if ($this->user()->can('create', RatingGuideAnswer::class)) {
22
            $questionId = (int) $this->input("rating_guide_question_id");
23
            if ($questionId) {
24
                $question = RatingGuideQuestion::find($questionId);
25
                return $question && $question->job_poster->manager->user_id === $this->user()->id;
26
            }
27
        }
28
        return false;
29
    }
30
31
    /**
32
     * Get the validation rules that apply to the request.
33
     *
34
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \App\Http\Requests\StoreRatingGuideAnswer::rules() does not specify type hint for items of its traversable return value.
Loading history...
35
     */
36
    public function rules()
0 ignored issues
show
introduced by
Method \App\Http\Requests\StoreRatingGuideAnswer::rules() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
37
    {
38
        return [
39
            'rating_guide_question_id' => ['required', new ValidIdRule(RatingGuideQuestion::class)],
40
            'criterion_id' => ['nullable', new ValidIdRule(Criteria::class)],
41
            'expected_answer' => 'nullable|string',
42
        ];
43
    }
44
}
45