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

UpdateRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 8 8 2
A rules() 7 7 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\Discussions\Traits\SavesDiscussion;
7
use FaithGen\SDK\Helpers\Helper;
8
use Illuminate\Foundation\Http\FormRequest;
9
10 View Code Duplication
class UpdateRequest 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
    use SavesDiscussion;
13
14
    /**
15
     * Determine if the user is authorized to make this request.
16
     *
17
     * @param  DiscussionService  $discussionService
18
     *
19
     * @return bool
20
     */
21
    public function authorize(DiscussionService $discussionService)
22
    {
23
        if (! $discussionService->getDiscussion()) {
24
            return false;
25
        }
26
27
        return $this->user()->can('update', $discussionService->getDiscussion());
28
    }
29
30
    /**
31
     * Get the validation rules that apply to the request.
32
     *
33
     * @return array
34
     */
35
    public function rules()
36
    {
37
        return array_merge([
38
            'discussion_id' => Helper::$idValidation,
39
            'title'         => 'required|string',
40
        ], $this->getSaveRules());
41
    }
42
}
43