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

CommentRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 36
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 8 8 2
A rules() 7 7 1
A failedAuthorization() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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