Completed
Push — master ( 8fcc32...ae3918 )
by Innocent
01:13
created

CommentRequest::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Faithgen\Discussions\Http\Requests;
4
5
use Faithgen\Discussions\Services\DiscussionService;
6
use FaithGen\SDK\Helpers\Helper;
7
use Illuminate\Auth\Access\AuthorizationException;
8
use Illuminate\Foundation\Http\FormRequest;
9
10 View Code Duplication
class CommentRequest extends FormRequest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @param  DiscussionService  $discussionService
16
     *
17
     * @return bool
18
     */
19
    public function authorize(DiscussionService $discussionService)
20
    {
21
        if (! $discussionService->getDiscussion()) {
22
            return false;
23
        }
24
25
        return $this->user()->can('view', $discussionService->getDiscussion());
26
    }
27
28
    /**
29
     * Get the validation rules that apply to the request.
30
     *
31
     * @return array
32
     */
33
    public function rules()
34
    {
35
        return [
36
            'discussion_id' => Helper::$idValidation,
37
            'comment'       => 'required|string',
38
        ];
39
    }
40
41
    public function failedAuthorization()
42
    {
43
        throw new AuthorizationException('You are not allowed to comment on this discussion');
44
    }
45
}
46