Passed
Push — master ( 3b518a...cd2a02 )
by Adam
11:23
created

CommentRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 23 2
A authorize() 0 3 1
1
<?php
2
3
namespace Coyote\Http\Requests;
4
5
use Coyote\Comment;
6
use Coyote\Job;
7
use Coyote\Guide;
8
use Illuminate\Foundation\Http\FormRequest;
9
use Illuminate\Validation\Rule;
10
11
class CommentRequest extends FormRequest
12
{
13
    /**
14
     * Determine if the user is authorized to make this request.
15
     *
16
     * @return bool
17
     */
18
    public function authorize()
19
    {
20
        return true;
21
    }
22
23
    /**
24
     * Get the validation rules that apply to the request.
25
     *
26
     * @return array
27
     */
28
    public function rules()
29
    {
30
        /** @var Comment $comment */
31
        $comment = $this->route('comment');
32
        $rule = Rule::requiredIf(!$comment->exists && !$this->input('parent_id'));
33
34
        return [
35
            'text' => 'required|string',
36
            'parent_id' => [
37
                'nullable',
38
                'int',
39
                Rule::exists('comments', 'id')->whereNull('parent_id')
40
            ],
41
            'resource_id' => [
42
                'bail',
43
                $rule,
44
                'nullable',
45
                'int'
46
            ],
47
            'resource_type' => [
48
                'bail',
49
                $rule,
50
                Rule::in([Guide::class, Job::class])
51
            ]
52
        ];
53
    }
54
}
55